標籤:bsp 網站 top ati out 簡單 實現 seo ndt
CSS樣式:
<style>*{margin:0; padding:0;}ul,li{list-style:none;}a{text-decoration:none;}img{border:none; vertical-align:top;}#notice{width:500px; height:40px; position:relative; overflow:hidden; margin:50px auto; border:1px solid #CCC;}#notice ul{position:absolute;left:0; top:0;}#notice ul li{width:100%; height:40px; line-height:40px; text-indent:20px;}</style>
HTML結構:
<div id="notice"> <ul> <li><a href="#">就讓那一切成流水把那往事</a></li> <li><a href="#">把那往事當作一場宿醉</a></li> <li><a href="#">明日的酒杯莫再要裝著昨天的傷悲</a></li> </ul></div>
JS代碼實現(需先匯入jquery庫檔案):
function moveTop(obj,num,tag1,tag2){ //容器元素 滾動行數 父元素 子項目 var iH = $(obj).find(tag2).height(); $(obj+tag1).css(‘height‘,iH * $(obj).find(tag2).length); $(obj).find(tag1).animate({‘top‘:iH*num},500,function(){ $(this).css({top:0}).find(‘tag2:first‘).appendTo(this); });}var timer = null;timer = setInterval(‘moveTop(".notice",1,"ul","li")‘,3000); //自動輪播$(".notice").hover(function(){ //滑鼠移入時停止自動輪播(滑鼠移入移出事件也可用mouseover和mouseout來實現) clearInterval(timer); },function(){ timer = setInterval(‘moveTop(".notice",1,"ul","li")‘,3000); //滑鼠移出時繼續自動輪播});
簡單jQuery網站公告逐行輪播效果