js實現文字滾動輸入效果

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			*{margin: 0;padding: 0;}
			#txt1{background: #0084BB;margin-bottom: 10px;}
			#txt2{background: pink;}
		</style>
		<script type="text/javascript">
			window.onload = function(){
				var	aDiv = document.getElementsByTagName('div');
				// console.log(aDiv[0])
				
				// console.log(txt1)
				// aDiv[1].innerText = txt1.join('');
				var text = '';
				setInterval(function(){
					var txt1 = aDiv[0].innerText.split('');
					text += txt1.splice(0,1);
					aDiv[0].innerText = txt1.join('');
					// console.log(txt1)
					aDiv[1].innerText = text;
				},1000);
					
				
			}
		</script>
	</head>
	<body>
		<div id="txt1">內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容內容</div>
		<div id="txt2"></div>
	</body>
</html>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章