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. 如何跟踪页面上链接点击的位置?
- 5. Android EditText的光标位置跟踪点击或按第一次点击
- 6. 跟踪点击Flash广告
- 7. KnockoutJS:跟踪菜单点击
- 8. 跟踪点击链接
- 9. IFrame跨域点击跟踪
- 10. 按钮点击跟踪
- 11. AS3 - 跟踪 - 点击按钮
- 12. 在android中跟踪位置
- 13. 背景位置跟踪:iOS
- 14. html5地理位置跟踪
- 15. 实时位置跟踪
- 16. 排序后跟踪位置
- 17. cllocation跟踪一个位置
- 18. 地理位置跟踪
- 19. 跟踪点击锚点电话链接
- 20. 跟踪链接点击Google跟踪代码管理器
- 21. 用户邮件跟踪位置(在阅读邮件时跟踪用户位置)
- 22. 跟踪点击通话移动功能
- 23. jQuery:使用PHP进行点击跟踪
- 24. 跟踪x-webkit-speech的点击
- 25. 元素点击次数跟踪
- 26. 跟踪Google AdWords点击Facebook iframe标签
- 27. 跟踪jquery里面的iframe的点击
- 28. 跟踪IP地址点击图片
- 29. 如何使用Ahoy Gem跟踪点击
- 30. 跟踪点击出站链接
咦,这是接近,但值是很多大于100,而当浏览器大小的变化,从700 +到900+。这不完全是'div'中的位置,其宽度范围从100px到150px(实际上它是100%宽度'div') – jolt 2011-05-29 16:56:18