Scroll a div from everywhere

2020-02-07 13:37发布

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 scroll wheel to scroll this div also. Whether you are with the mouse over the div or outside.

sorry for my bad english, google translator .... embarrassing ^_^

Update: https://github.com/brandonaaron/jquery-mousewheel Thank you... thats worked on all browser but not on the ipad... is it possible on ipad? –

2条回答
小情绪 Triste *
2楼-- · 2020-02-07 13:59

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/

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2020-02-07 14:08

Try using JQuery. On document ready you focus on the div. You make the div scrollable by setting the overflow property in css.

JQuery:

$(document).ready(function(){ $( "#scrollable_div" ).focus(); }

CSS:

#scrollable_div {
    overflow: scroll;
}
查看更多
登录 后发表回答