从任何地方滚动一个 div [英] Scroll a div from everywhere

查看:16
本文介绍了从任何地方滚动一个 div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何描述我的担忧,这就是我在 Google 上找不到任何内容的原因.我想绘制一个 div 立即聚焦在页面调用上,如果您按下滚轮也可以滚动此 div.无论您是将鼠标悬停在 div 上还是在外面.

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 ^_^

更新:https://github.com/brandonaaron/jquery-mousewheel 谢谢... 可以在所有浏览器上运行,但不能在 ipad 上运行……是否可以在 ipad 上使用?——

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

推荐答案

如果你想滚动 div,即使鼠标在页面上的其他位置,试试这个插件 https://github.com/brandonaaron/jquery-mousewheel.这是一个假设您的 div 具有内容 ID 的示例:

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();
   });
});

快速小提琴:http://jsfiddle.net/5h47wygo/

这篇关于从任何地方滚动一个 div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆