gpt4 book ai didi

Javascript 更改 css top 属性

转载 作者:太空宇宙 更新时间:2023-11-04 14:17:54 24 4
gpt4 key购买 nike

您好,我正在尝试在我的网页上单击按钮时逐渐更改背景,这是一个 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 属性。 See fiddle

关于Javascript 更改 css top 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20162333/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com