JQuery变量在悬停状态下滚动。我怎样才能使它在鼠标退出后变得轻松?

JQuery变量在悬停状态下滚动。我怎样才能使它在鼠标退出后变得轻松?,jquery,scroll,smooth-scrolling,custom-scrolling,Jquery,Scroll,Smooth Scrolling,Custom Scrolling,好的,我想解释一下,但是有点难。假设我有一些像这样的html <div id="wrapper"> <div id="scroll"> <!--content--> </div> </div> 现在,包装器有一个设定的高度,比如500px,滚动一个更长的高度,比如3000px 这是什么,当用户在包装纸上徘徊或下沉时,卷轴滚动得更快,中间有一个死区。但当用户从包装器上滚下时,它会突然停止。当用户停止悬停

好的,我想解释一下,但是有点难。假设我有一些像这样的html

<div id="wrapper">
    <div id="scroll">
        <!--content-->
    </div>
</div> 
现在,包装器有一个设定的高度,比如500px,滚动一个更长的高度,比如3000px


<>这是什么,当用户在包装纸上徘徊或下沉时,卷轴滚动得更快,中间有一个死区。但当用户从包装器上滚下时,它会突然停止。当用户停止悬停在包装器上时,我可以如何使其优雅地停止?也欢迎对我的代码进行优化

查看jQuery事件mouseout。我建议您将这样的事件附加到包装器,并使用已经设置的速度变量从那里平稳地停止动画

var hoverInterval, yPos, offset, objHeight

$("#wrapper").mousemove(function(e){
    //when the mouse moves in #wrapper, find the height of the object
    //and the relative position of the mouse within the object.
    objHeight = this.offsetHeight
    yPos = e.pageY - this.offsetTop;
});
$("#wrapper").hover( //when the user hovers w/i #wrapper...
    function(){
        hoverInterval = setInterval(function(){
            factor = (100*yPos)/objHeight //gives a range from 0-100
            move = ( -3+( ( Math.pow(factor-50,2))/56))/8
                      /*this provides a bell curve, so that as 
                       *the user hovers closer to the extremes,
                       */#scroll will scroll faster up and down.
                if ( move > 0 ) { //prevents movement when in the middle
                if (yPos <= objHeight*.5 ) {
                    $("#photos").animate(
                          {"top":"+="+move+"px"},"slow","easeOutExpo")
                          .stop("true","true")
                }
                else if (yPos >= objHeight*.5){
                    $("#photos").animate(
                          {"top": "-="+move+"px"},"slow","easeOutExpo")
                          .stop("true","true")
                }
            }
        },10); //setInterval's timeout
    },
    function(){ //and stop at mouse off.
        clearInterval(hoverInterval)
    }
);