jQuery scroll a div up and down using two buttons

后端 未结 4 2220
执念已碎
执念已碎 2021-02-10 13:45

I have a simple set of two buttons that when hovered should make a div move up and down to simulate a scrolling effect:

$(\"#down\").hover(function () {

    $(\         


        
4条回答
  •  故里飘歌
    2021-02-10 14:43

    I think animate is more useful for single animation effects rather than a continuous and variable change. You can implement this yourself with an interval.

    var interval;
    
    $("#down").mouseenter(function () {
        interval = setInterval(ScrollDown, 100);
    });
    
    $("#down").mouseleave(function () {
        clearInterval(interval);
    });
    
    function ScrollDown() {
        $('.scroll').css("marginTop", "+=50px");
        // check bounds here to solve problem #1
    }
    
    /* do the same stuff for scrolling up */
    

提交回复
热议问题