var currentPosition = 0;var moveVal = 25;$(document).keydown(function(e){ switch (e.which){ case 37: //left arrow key currentPosition += moveVal; break; case 39: //right arrow key currentPosition -= moveVal; break; } startMovement(); setBgPos(currentPosition);});$(document).keyup(function(e){ endMovement()});function startMovement() { $('#matteo-walking').addClass('movement');}function endMovement() { $('#matteo-walking').removeClass('movement');}function setBgPos(currentPosition) { $('#matteo-container').css('background-position', currentPosition + 'px -300px');}谢谢 这篇关于按下一个键时继续移动元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-19 09:07