<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
</head>
<body>
<style>
#marquee{width: 252px;height: 30px;}
#marquee p{height:30px;line-height: 30px;margin:0;float: left;}
</style>
<div style="height:30px;overflow:hidden;">
<div id='marquee'>
<p>第1段</p>
<p>第2段</p>
<p>第3段</p>
<p>第4段</p>
<p>第5段</p>
</div>
</div>
<script>
(function(){
var marquee = document.getElementById('marquee');
var offset=0;
// var scrollheight =marquee.offsetWidth;
// console.log(scrollheight)
var firstNode = marquee.children[0].cloneNode(true);
marquee.appendChild(firstNode);//还有这里
setInterval(function(){
if(offset == 252){
offset = 0;
}
marquee.style.marginLeft = "-"+offset+"px";
offset += 1;
},50);
})();
</script>
</body></html>
js文字轮播
最新推荐文章于 2024-05-19 18:43:23 发布