0

我有一个简单演示的查询,我想在button1点击时停止滚动,button2然后滚动将恢复。我不知道我是怎么做到的?

小提琴here

HTML:

<input type='button' value='stop scroll' id='btn1'>
    <input type='button' value='resume scroll' id='btn2'>
        <div> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, ... <div>
4

2 回答 2

2

你想要这个吗?

$(document).ready(function(){
    var allowScroll = true;

    $("div").on('mousewheel DOMMouseScroll',function(e){ 
       if (!allowScroll){
          e.preventDefault();
       }
    });

    $('#btn1').click(function(){
       allowScroll = false;
    });

    $('#btn2').click(function(){
       allowScroll = true;
    });

});

演示

于 2013-10-14T14:29:30.503 回答
0

我认为您可以为“mousewheel”事件添加一个处理程序(使用jquery-mousewheel来支持浏览器)并执行以下操作:

$('#my_elem').bind('mousewheel', function(event, delta, deltaX, deltaY) {
    event.preventDefault(); //to prevent the default action
    // or $("html, body").scrollTo(0);
});
于 2013-10-14T14:33:49.337 回答