0

I am trying to get the current mouse position in javascript with this simple sample code:

$(document).mousemove(function(e){
    console.log(e.pageX +', '+ e.pageY);
});

This works fine but I want to get the current mouse position on elements like <object>. Namely I am using jQuery Media Plugin jQuery.media.js which generates the proper media element depending on the browser used. With demos like this the console stops logging as long as I stay on the media element. For instance I copy pasted this code:

<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="jquery.media.js"></script>
<script>
$(document).ready(function(){
    $('.media').media();
});
$(document).mousemove(function(e){
    console.log(e.pageX +', '+ e.pageY);
});
</script>
</head>
<body>
    <a class="media {width:480, height:280}" href="http://malsup.github.com/video/simpsons.mov">MOV File (video)</a> 
</body>

Can I use a different event? Or is this media element not part of $(document)?

4

1 回答 1

2

插件渲染的 DOM 元素不是标准的 DOM 元素。他们不必向浏览器发送任何事件。如果它是您尝试显示的电影,请使用 HTML5<video>标记 - 它应该正确触发所有标准 DOM 事件。如果这不是一个选项,您可以尝试div在电影上放置一个透明的。它应该正确触发所有事件。这里唯一的缺点是电影本身不可点击(控件等)。

于 2012-06-11T09:45:09.050 回答