2012-01-15 108 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