2 回答

TA貢獻(xiàn)9條經(jīng)驗(yàn) 獲得超3個(gè)贊
再試試
<!Doctype html>
<html>
? ? <head>
? ? ? ? <meta charset="utf-8" />
? ? ? ? <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
? ? ? ? <title>調(diào)試</title>
? ? ? ? <style>
? ? ? ? ? ? *{margin:0; padding:0; color:black;}
? ? ? ? ? ? ul{list-style:none;}
? ? ? ? ? ? a{text-decoration:none;}
? ? ? ? ? ? a:hover{color:orange;}
? ? ? ? ? ? #articleList{width:400px; border:5px solid gray;}
? ? ? ? ? ? #articleTitle{height:50px; line-height:50px; font-size:24px; text-align:center; border-bottom:1px solid gray;}
? ? ? ? ? ? #articleContent{width:350px; height:125px; margin:10px 25px; overflow:hidden;}
? ? ? ? ? ? #articleContent ul li a{width:200px; height:25px; line-height:25px; display:inline-block; padding-left:15px; overflow:hidden;}
? ? ? ? ? ? #articleContent ul li span{float:right; color:gray;}
? ? ? ? </style>
? ? ? ? <script>
? ? ? ? ? ? window.onload = function(){
? ? ? ? ? ? ? ? var area = document.getElementById("articleContent");
? ? ? ? ? ? ? ? var newList = document.getElementById("newList");
? ? ? ? ? ? ? ? var newListTemp = document.getElementById("newListTemp");
? ? ? ? ? ? ? ? var speed = 50;
? ? ? ? ? ? ? ? area.scrollTop = 0;
? ? ? ? ? ? ? ? newListTemp.innerHTML = newList.innerHTML;
? ? ? ? ? ? ? ? var myScroll = setInterval(scrollUp, speed);
? ? ? ? ? ? ? ? area.onmouseover = function(){
? ? ? ? ? ? ? ? ? ? clearInterval(myScroll);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? area.onmouseout = function(){
? ? ? ? ? ? ? ? ? ? myScroll = setInterval(scrollUp, speed);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? function scrollUp(){
? ? ? ? ? ? ? ? ? ? if(area.scrollTop >= newList.scrollHeight){
? ? ? ? ? ? ? ? ? ? ? ? area.scrollTop = 0;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? else{
? ? ? ? ? ? ? ? ? ? ? ? area.scrollTop ++;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }?
? ? ? ? ? ? }
? ? ? ? </script>?
? ? </head>
? ? <body>
? ? ? ? <div id="articleList">
? ? ? ? ? ? <h3 id="articleTitle">最近更新文章</h3>
? ? ? ? ? ? <div id="articleContent">
? ? ? ? ? ? ? ? <ul id="newList">
? ? ? ? ? ? ? ? ? ? <li><a href="#">1.做對(duì)自己有意義的事</a><span>2016-05-28</span></li>
? ? ? ? ? ? ? ? ? ? <li><a href="#">2.關(guān)于CSS選擇器繼承</a><span>2016-05-30</span></li>
? ? ? ? ? ? ? ? ? ? <li><a href="#">3.自己動(dòng)手,豐衣足食</a><span>2016-06-01</span></li>
? ? ? ? ? ? ? ? ? ? <li><a href="#">4.論inline-block</a><span>2016-06-02</span></li>
? ? ? ? ? ? ? ? ? ? <li><a href="#">5.更多正在編寫(xiě)中……</a><span>2016-06-02</span></li>
? ? ? ? ? ? ? ? </ul>
? ? ? ? ? ? ? ? <ul id="newListTemp"></ul>
? ? ? ? ? ? </div>
? ? ? ? </div>
? ? </body>
</html>

TA貢獻(xiàn)9條經(jīng)驗(yàn) 獲得超3個(gè)贊
js中可以用window onload() ?代表頁(yè)面全部加載完成之后在執(zhí)行之下的代碼
<!Doctype html>
<html>
? ? <head>
? ? ? ? <meta charset="utf-8" />
? ? ? ? <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
? ? ? ? <title>調(diào)試</title>
? ? ? ? <style>
? ? ? ? ? ? *{margin:0; padding:0; color:black;}
? ? ? ? ? ? ul{list-style:none;}
? ? ? ? ? ? a{text-decoration:none;}
? ? ? ? ? ? a:hover{color:orange;}
? ? ? ? ? ? #articleList{width:400px; border:5px solid gray;}
? ? ? ? ? ? #articleTitle{height:50px; line-height:50px; font-size:24px; text-align:center; border-bottom:1px solid gray;}
? ? ? ? ? ? #articleContent{width:350px; height:125px; margin:10px 25px; overflow:hidden;}
? ? ? ? ? ? #articleContent ul li a{width:200px; height:25px; line-height:25px; display:inline-block; padding-left:15px; overflow:hidden;}
? ? ? ? ? ? #articleContent ul li span{float:right; color:gray;}
? ? ? ? </style>
? ? ? ? ?<script>
? ? ? ? ?window.onload = function(){
? ? ? ? ? var area = document.getElementById("articleContent");
? ? ? ? ? ? var newList = document.getElementById("newList");
? ? ? ? ? ? var newListTemp = document.getElementById("newListTemp");
? ? ? ? ? ? var speed = 50;
? ? ? ? ? ? area.scrollTop = 0;
? ? ? ? ? ? newListTemp.innerHTML = newList.innerHTML;
? ? ? ? ? ??
? ? ? ? ? ? function scrollUp(){
? ? ? ? ? ? ? ? if(area.scrollTop >= newList.scrollHeight){
? ? ? ? ? ? ? ? ? ? area.scrollTop = 0;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else{
? ? ? ? ? ? ? ? ? ? area.scrollTop ++;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? var myScroll = setInterval("scrollUp()", speed);
? ? ? ? ? ? area.onmouseover = function(){
? ? ? ? ? ? ? ? clearInterval(myScroll);
? ? ? ? ? ? }
? ? ? ? ? ? area.onmouseout = function(){
? ? ? ? ? ? ? ? myScroll = setInterval("scrollUp()", speed);
? ? ? ? ? ? }
? ? ? ? } ?
? ? ? ? </script>
? ? </head>
? ? <body>
? ? ? ? <div id="articleList">
? ? ? ? ? ? <h3 id="articleTitle">最近更新文章</h3>
? ? ? ? ? ? <div id="articleContent">
? ? ? ? ? ? ? ? <ul id="newList">
? ? ? ? ? ? ? ? ? ? <li><a href="#">1.做對(duì)自己有意義的事</a><span>2016-05-28</span></li>
? ? ? ? ? ? ? ? ? ? <li><a href="#">2.關(guān)于CSS選擇器繼承</a><span>2016-05-30</span></li>
? ? ? ? ? ? ? ? ? ? <li><a href="#">3.自己動(dòng)手,豐衣足食</a><span>2016-06-01</span></li>
? ? ? ? ? ? ? ? ? ? <li><a href="#">4.論inline-block</a><span>2016-06-02</span></li>
? ? ? ? ? ? ? ? ? ? <li><a href="#">5.更多正在編寫(xiě)中……</a><span>2016-06-02</span></li>
? ? ? ? ? ? ? ? </ul>
? ? ? ? ? ? ? ? <ul id="newListTemp"></ul>
? ? ? ? ? ? </div>
? ? ? ? </div>
? ? </body>
</html>
添加回答
舉報(bào)