开发者

One document.getElementById per function?

I'm trying to use mouse coordinates to control the opacity of div elements, bu开发者_运维百科t only one div element will respond.

<head>
document.onmousemove=getMouseCoordinates;

function getMouseCoordinates(event)
{
ev = event || window.event;
var width = window.innerWidth;
document.getElementById('divOne').style.opacity = ev.pageX/width;
document.getElementById('divOne').style.filter = 'alpha(opacity=' + value*10 + ')';
document.getElementById('divTwo').style.opacity = ev.pageX/width;
document.getElementById('divTwo').style.filter = 'alpha(opacity=' + value*10 + ')';
}
</head>
<body>
<div id="divOne" style="position:fixed; top:7%; left: 11%;"><img src="images/skytest.png" /></div>
<div id="divTwo" style="position:fixed; top:22%; left: 26%;"><img src="images/0816112011d.jpeg" /></div>

divOne does what I would expect, but divTwo does nothing. Anything I'm forgetting?


According to your code, the only problem is that the js isn't in a script tag. Otherwise there's no difference.

See this very easy to make demo :D

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜