用鼠标移动滚动页面

时间:2014-07-22 07:20:54

标签: jquery html5

我的html页面包含" Nestable"拖放菜单。我的问题是当我拖动一些东西然后放在页面的末尾时,它需要向下滚动页面,反之亦然。如何使用jQuery或JavaScript?

1 个答案:

答案 0 :(得分:1)

尝试这段代码here

也许在拖放时调用此功能,也可以尝试使用高度来判断何时希望页面向上/向下滚动,目前它位于屏幕中间的某个位置。

 $(document).mousemove(function(e) {
   $("html, body").scrollTop(function(i, v) {
      var h = $(window).height();
      var y = e.clientY - h / 2;   //determins the y location where your scrolling starts
      return v + y * 0.1;          //0.1 determines the speed
    });
 });

编辑 here 是一个更平滑的过渡,有点复杂但你仍然可以理解发生了什么

相关问题