我在頁面頂部有一個圖像,並希望它從靜止變爲左側,然後右側,具體取決於您在頁面上的鼠標位置。請幫助我用鼠標位置改變圖像
-1
A
回答
2
最好的辦法是利用文檔上的mousemove
函數,然後使用event參數跟蹤鼠標位置。
這裏是JSFiddle example。
$(document).mousemove(function(event){
var mloc = {
x: event.pageX,
y: event.pageY
};
if(
(mloc.x >= 0 && mloc.x <= $(document).width()/2) &&
(mloc.y >= 0 && mloc.y <= $(document).height()/2)
){
//In upper left corner
//Do stuff
}else if(
(mloc.x >= $(document).width()/2 && mloc.x <= $(document).width()) &&
(mloc.y >= 0 && mloc.y <= $(document).height()/2)
){
//In upper right corner
//Do stuff
} //etc
});
Here's a tutorial關於鼠標跟蹤。
Here's a whole bunch可用事件的東西。
+0
完美的作品,謝謝sooo多ShadowScripter – 2012-02-28 17:01:56
+0
@JoshKing很高興我可以幫助:) – ShadowScripter 2012-02-28 17:04:12
相關問題
- 1. 根據鼠標位置改變圖像
- 2. 用javascript的鼠標位置改變圖像?
- 3. 縮放圖像進出也改變JscrollPane accroding到鼠標位置
- 4. CSS:鼠標懸停改變圖像的位置和大小
- 5. 鼠標光標位置改變
- 6. jQuery改變圖像位置
- 7. 鼠標單擊圖像上的位置
- 8. 確定圖像上的鼠標位置
- 9. 鼠標懸停改變圖像
- 10. 鼠標XY改變圖像飽和度
- 11. 在鼠標上方改變圖像
- 12. 更改鼠標位置
- 13. Gridview ImageButton改變鼠標懸停和鼠標移動的圖像
- 14. 基於鼠標位置的兩個圖像之間的更改
- 15. 用JavaScript改變圖像的位置
- 16. 處理:試圖讓臉部通過鼠標位置改變
- 17. 圖片角度改變鼠標的依賴位置
- 18. 改變圖像懸停,但不改變圖像位置
- 19. 獲取/設置地圖圖像鼠標位置
- 20. 如何在鼠標上改變另一圖像的圖像
- 21. CakePHP的改變圖像時鼠標在圖像上
- 22. 鼠標位置()
- 23. 更改背景顏色,改變鼠標位置
- 24. 如何使用Cocoa改變鼠標位置差異?
- 25. 從JS執行mouseover()而不用改變鼠標的位置
- 26. 用鼠標位置改變不透明度
- 27. 改變最後的圖像的位置
- 28. 運行時改變圖像位置
- 29. CSS懸停圖像位置改變
- 30. 改變CKEditor尋找圖像的位置
到目前爲止我的代碼只能與點擊 ____________________________________________________________________ $( 「face_one 」)。點擊(函數(){ \t \t \t \t $(「 臉 」)。ATTR(「 SRC」,「 images/faces/face_one.png「); \t \t \t \t }); \t \t \t \t $( 「face_two 」)。點擊(函數(){ \t \t \t \t \t $(「 臉 」)。ATTR(「 SRC」, 「圖像/面/ face_two.png」 ); \t \t \t \t \t}); \t \t \t \t $( 「face_three 」)。點擊(函數(){ \t \t \t \t \t $(「 臉 」)。ATTR(「 SRC」, 「圖像/面/ face_three.png」 ); \t \t \t \t \t}); – 2012-02-28 05:28:50
這裏是一個教程,你可能會發現有幫助: http://docs.jquery.com/Tutorials:Mouse_Position#Tracking_mouse_position – kappamaki 2012-02-28 05:34:07