0
Q
點擊跟蹤位置
A
回答
0
管理與執行此操作:
$('#song-seeker').click(function(e){
var offset = $(this).offset(); // somehow this.offsetLeft didn't work
var x = Math.floor(e.pageX - offset.left); // calculates pixel value of position clicked within element
x = Math.floor(x * 100/$(this).width()); // transform to % value based on full clicked elements width
// Math.floor() used to prepare values with 0 values behind comma, therefore, CSS safe.
});
1
試試這個:
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
$("#special").click(function(e){
var xP = e.pageX * 100/$(e.target).width();
var yP = e.pageY * 100/$(e.target).height();
$('#status2').html(xP +', '+ yP);
});
})
</script>
<body>
<h2 id="status2">
0, 0
</h2>
<div style="width: 100px; height: 100px; background:#ccc;" id="special">
Click me anywhere!
</div>
</body>
</html>
相關問題
- 1. 跟蹤位置
- 2. 位置跟蹤
- 3. 用jQuery跟蹤點擊 - php跟蹤
- 4. 點擊與DoubleClick點擊跟蹤標籤跟蹤
- 5. Div位置跟蹤
- 6. 如何跟蹤頁面上鍊接點擊的位置?
- 7. Android EditText的光標位置跟蹤點擊或按第一次點擊
- 8. 自動Android點擊/點擊跟蹤
- 9. 覆蓋點擊跟蹤
- 10. IFrame跨域點擊跟蹤
- 11. 跟蹤點擊鏈接
- 12. Android - 跟蹤用戶點擊
- 13. AS3 - 跟蹤 - 點擊按鈕
- 14. KnockoutJS:跟蹤菜單點擊
- 15. 跟蹤點擊Flash廣告
- 16. 與跟蹤問題點擊
- 17. Sitecore跟蹤頁面點擊
- 18. 按鈕點擊跟蹤
- 19. 跟蹤互動PDF點擊
- 20. 朋友的跟蹤位置
- 21. 跟蹤boost :: spirit的位置
- 22. 地理位置跟蹤
- 23. cllocation跟蹤一個位置
- 24. html5地理位置跟蹤
- 25. 排序後跟蹤位置
- 26. 跟蹤手機的位置
- 27. 跟蹤用戶位置
- 28. 實時位置跟蹤
- 29. 在android中跟蹤位置
- 30. 背景位置跟蹤:iOS
咦,這是接近,但值是很多大於100,而當瀏覽器大小的變化,從700 +到900+。這不完全是'div'中的位置,其寬度範圍從100px到150px(實際上它是100%寬度'div') – jolt 2011-05-29 16:56:18