1. 程式人生 > 其它 >原生js訊息無縫輪播

原生js訊息無縫輪播

技術標籤:程式碼片段javascripthtml5css

在這裡插入圖片描述

<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8" />
	<title>滾動輪播</title>
</head>

<style type="text/css">
	body {
		background-color: cornflowerblue;
	}

	._container {
		height: 36px;
		overflow: hidden;
border-bottom: 1px solid #ccc; text-align: center; margin: 300px auto; padding: 0; } ._container li { height: 36px; line-height: 36px; font-size: 18px; color: #fff; } ._container li:first-child { margin-top: 0; transition: margin-top 1s; }
</style> <body> <ul class
="_container" id="demo">
<li>第一條訊息</li> <li>第二條訊息</li> <li>第三條訊息</li> <li>第四條訊息</li> <li>第五條訊息</li> <li>第六條訊息</li> </ul> </body> <script type="text/javascript"> /*啟動方式*/ /* * demo 父容器(ul)的 * _h 子元素li的高度 * interval 滾動間隔時間 * transition輪播動畫時間 */
function Scroll() {} Scroll.prototype.upScroll = function (dom, _h, interval) { var dom = document.getElementById(dom); var _heigth = "-" + _h + 'px' var timer = setTimeout(function () { var _field = dom.firstElementChild; _field.style.marginTop = _heigth; clearTimeout(timer); }, 0) setInterval(function () { var _field = dom.firstElementChild; _field.style.marginTop = "0px"; dom.appendChild(_field); var _field = dom.firstElementChild _field.style.marginTop = _heigth; }, interval) } var myScroll = new Scroll(); myScroll.upScroll("demo", 36, 3000);
</script> </html>

vue+ts版本訊息輪播:https://blog.csdn.net/weixin_42513555/article/details/113759068

Vue+ts訊息無縫輪播2.0版本:https://blog.csdn.net/weixin_42513555/article/details/113760493