2012-01-15 46 views

回答

2

我们不能确切地只是给你你的答案,但作为暗示,你将不得不使用mousemove事件,并检测面板内的鼠标在哪里。设置overflow: hidden;并将相对速度移到鼠标靠近边缘的位置。我建议使用两个div - 一个外部div来设置边界(在此div上检测mousemove),然后另一个绝对定位。

这将是这样的:

HTML:

<div id='outer'> 
    <div id='inner'> 
     <p>Overflowing content here</p> 
    </div> 
</div> 

CSS:

#outer { 
    height: 200px; 
    width: 150px; 
    position: relative; 
} 

#inner { 
    position: absolute; left: 0; top: 0; right: 0; bottom: 0; overflow: hidden; 
} 

的jQuery:

$(document).ready(function() { 
    $("#outer").mousemove(function(e) { 
     //Refer to [here][1] to get position of mouse within element. 
     //Get position of mouse within the element, if it is at the top then compare how close it is to 0, if it is at the bottom then compare how close it is to 200px (or whatever you set as the height of the outer container). Slide inner container as appropriate. 
    }); 
}); 
4

看看这个我有固定别人的代码:http://jsfiddle.net/n3Q9j/5/

+0

非常好的解决方案,但在我的情况下动画并不流畅,所以我添加了一个标志,以便在一个循环中间发信号 – 2014-03-12 12:25:27

+0

@MosheShaham你能分享一下你做了什么吗?我得到了类似的不流畅,但这只是我在JQuery的第二次尝试,所以我不知道如何解决它。 – Nerrolken 2014-05-06 03:41:19