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