各位高手好!js实现div移动的动画,为什么div的css要写在div属性里才行,写在js里不行呢?
答案:1 悬赏:80
解决时间 2021-02-07 21:41
- 提问者网友:喜遇你
- 2021-02-07 09:41
各位高手好!js实现div移动的动画,为什么div的css要写在div属性里才行,写在js里不行呢?
最佳答案
- 二级知识专家网友:糜废丧逼
- 2021-02-07 10:21
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>
RunJS 演示代码
</title>
<style>
#aa{
position:absolute;
border: 1px solid #fd3;
left: 0px;
top: 0px;
}
</style>
<script>
onload = function()
{
var aa= document.getElementById("aa");
setInterval(function(){
var l = parseFloat(aa.style.left) || aa.offsetLeft;
l = l > 300 ? 0 : l;
aa.style.left = l + 1 + "px";
},10);
}
</script>
</head>
<body>
<div id="aa">
ddd
</div>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>
RunJS 演示代码
</title>
<style>
#aa{
position:absolute;
border: 1px solid #fd3;
left: 0px;
top: 0px;
}
</style>
<script>
onload = function()
{
var aa= document.getElementById("aa");
setInterval(function(){
var l = parseFloat(aa.style.left) || aa.offsetLeft;
l = l > 300 ? 0 : l;
aa.style.left = l + 1 + "px";
},10);
}
</script>
</head>
<body>
<div id="aa">
ddd
</div>
</body>
</html>
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯