Javascript 在鼠标上以固定速度轻松地移入和移出背景图像
我需要的背景图像向左或向右移动的基础上,鼠标移动。我想轻松地做这件事。我还希望无论鼠标移动的速度有多快,都能固定移动的速度(缓慢和平滑)。移动也需要限制在一定距离内。我已经找到了一种使背景移动的方法,但是找不到一种轻松进出的方法。我检查了类似的问题,但找不到明确的解决方案 CSSJavascript 在鼠标上以固定速度轻松地移入和移出背景图像,javascript,jquery,Javascript,Jquery,我需要的背景图像向左或向右移动的基础上,鼠标移动。我想轻松地做这件事。我还希望无论鼠标移动的速度有多快,都能固定移动的速度(缓慢和平滑)。移动也需要限制在一定距离内。我已经找到了一种使背景移动的方法,但是找不到一种轻松进出的方法。我检查了类似的问题,但找不到明确的解决方案 CSS body.landing #page-wrapper { background-image: url("sample-img.png"); background-attachment
body.landing #page-wrapper {
background-image: url("sample-img.png");
background-attachment: fixed;
background-position: center center;
background-repeat: repeat;
background-size: cover;
$(document).ready(function(){
$('#page-wrapper').mousemove(function(e){
var x = -(e.pageX + this.offsetLeft) / 10;
$(this).css('background-position', x + 'px ');
});
JS
body.landing #page-wrapper {
background-image: url("sample-img.png");
background-attachment: fixed;
background-position: center center;
background-repeat: repeat;
background-size: cover;
$(document).ready(function(){
$('#page-wrapper').mousemove(function(e){
var x = -(e.pageX + this.offsetLeft) / 10;
$(this).css('background-position', x + 'px ');
});