嗨,我正在尝试逐步改变我的网页上单击按钮的背景,这是一个javascript和html代码片段,我在做什么错呢?
var content=document.getElementById('content').style;
var content1 = document.getElementById('content1').style;
var start1;
var start2;
var inti =null;
function changeContent(){
start1 =1;
start2 = 1001;
inti=setInterval('swapContent()',20);
}
function swapContent(){
start1 -=5;
start2 -=5;
content.top = start1 + 'px';
content1.top = start2 + 'px';
}
<body>
<div id="navigation" >
<input type="button" onclick="changeContent()" />
</div>
<div id="content">
</div>
<div id="content1">
</div>
</body>
如果您希望样式top
起作用,则应设置css position属性。见小提琴
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句