Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/427.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在鼠标上以固定速度轻松地移入和移出背景图像_Javascript_Jquery - Fatal编程技术网

Javascript 在鼠标上以固定速度轻松地移入和移出背景图像

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

我需要的背景图像向左或向右移动的基础上,鼠标移动。我想轻松地做这件事。我还希望无论鼠标移动的速度有多快,都能固定移动的速度(缓慢和平滑)。移动也需要限制在一定距离内。我已经找到了一种使背景移动的方法,但是找不到一种轻松进出的方法。我检查了类似的问题,但找不到明确的解决方案

CSS

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 ');
    });