我正在编写一个脚本,让我的网站中的每个用户的光标跟随这样的图像:http://nextnews.us/content/index2.php但是当试图在wordpress模板上插入相同的脚本时,该工作不起作用,图像是保持静止!
<style>
#sendframe {
opacity:1.0;
position:absolute;
overflow:hidden;
top:50;
left:50;
}
</style>
<script type="text/javascript">
document.onmousemove = mouseMove;
function mouseMove(ev){
ev = ev || window.event;
var mousePos = mouseCoords(ev);
document.getElementById('sendframe').style.left=mousePos.x-30;
document.getElementById('sendframe').style.top=mousePos.y-23;
}
function mouseCoords(ev){
if(ev.pageX || ev.pageY){
return {x:ev.pageX, y:ev.pageY};
}
return {
x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
y:ev.clientY + document.body.scrollTop - document.body.clientTop
};
}
</script>
<div id="sendframe" style="display: ; position: absolute; opacity:1.0;filter:alpha(opacity=1);">
//here i will ad the image source
</div>
答案 0 :(得分:0)
您的问题是CSS规则中x和y坐标省略了“px”,例如top:50; left:50;
和document.getElementById('sendframe').style.left=mousePos.x-30;
Here is it working in JSFiddle
(并且请在下次尝试更好地格式化您的代码。将所有内容都标记出来并没有什么帮助。)