Scroll a div from everywhere

后端 未结 2 1809
梦如初夏
梦如初夏 2020-12-12 06:30

I do not know how to describe my concern and thats why I could not find anything on Google. I want to draw a div is focused at page call immediately and if you press the scr

2条回答
  •  眼角桃花
    2020-12-12 07:01

    If you want to scroll the div even if the mouse is else where on the page try this plugin https://github.com/brandonaaron/jquery-mousewheel. Here is an example assuming your div has an id of content:

    $(function() {
        var $target = $('#content');
        $("body").mousewheel(function(event, delta) {
          $target.scrollTop($target.scrollTop() - (delta * 30));
          event.preventDefault();
       });
    });
    

    Quick fiddle: http://jsfiddle.net/5h47wygo/

提交回复
热议问题