var myTimer;
var speed = 100; //速度毫秒 值越小速度越快
var stepSpeed = 4; //值越大越快
$(function() {
    var mybox = $(".scroll_box");
    //向上
    $(".scroll_up").bind("mouseover", function() {
        var nowPos = mybox[boxCount].scrollTop; //当前值
        changePos(mybox, nowPos, 0);
    }).bind("mouseout", function() {
        if (myTimer) { window.clearInterval(myTimer); }
    });
    //向下
    $(".scroll_down").bind("mouseover", function() {
        var nowPos = mybox[boxCount].scrollTop; //当前值
        var maxPos = mybox[boxCount].scrollHeight - mybox.outerHeight(); //最大值
        changePos(mybox, nowPos, maxPos);
    }).bind("mouseout", function() {
        if (myTimer) { window.clearInterval(myTimer); }
    });
});

function changePos(box, from, to) {
    if (myTimer) { window.clearInterval(myTimer); }
    var temStepSpeed = stepSpeed;
    if (from > to) {
        myTimer = window.setInterval(function() {
            if (box[boxCount].scrollTop > to) { box[boxCount].scrollTop -= (5 + temStepSpeed); temStepSpeed += temStepSpeed; }
            else { window.clearInterval(myTimer); }
        }, speed);
    } else if (from < to) {
        myTimer = window.setInterval(function() {
            if (box[boxCount].scrollTop < to) { box[boxCount].scrollTop += (5 + temStepSpeed); temStepSpeed += temStepSpeed; }
            else { window.clearInterval(myTimer); }
        }, speed);
    }
}

 

相关文章:

  • 2021-09-21
  • 2022-12-23
  • 2021-12-25
  • 2021-12-14
  • 2021-07-03
  • 2021-12-17
  • 2021-12-28
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-01
  • 2022-01-15
  • 2022-01-29
  • 2022-01-07
  • 2021-07-08
相关资源
相似解决方案