jQuery 實現公告無縫滾動

來源:互聯網
上載者:User

標籤:blog   class   java   ext   color   http   

 

HTML
<div id="hotTopic">
              <div class="wrap">
<ul id="talking">
    <li><a href="#">世界經典音樂劇《媽媽咪呀》1</a></li>
    <li><a href="#">阿童木</a></li>
    <li><a href="#">聖鬥士</a></li>
    <li><a href="#">喜羊羊與灰太狼</a></li>
    <li><a href="#">地球超人</a></li>
    <li><a href="#">變形金剛</a></li>
    <li><a href="#">迪士尼</a></li>
</ul>
<ul id="scroll"></ul>
</div>
</div>

JS

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript"> 
$(document).ready(function(){ 
var speed=30; 
var $tab=$("#hotTopic"); 
var $tab1=$("#talking"); 
var $tab2=$("#scroll"); 
$tab2.html($tab1.html()); 
function Marquee(){ 
 if($tab2[0].offsetWidth-$tab[0].scrollLeft<=0) 
 $tab[0].scrollLeft-=$tab1[0].offsetWidth; 
 else{ 
 $tab[0].scrollLeft++; 
 } 
 } 
var MyMar=setInterval(Marquee,speed);  
$tab.hover(function(){ 
        clearInterval(MyMar); 
        },function(){ 
        MyMar=setInterval(Marquee,speed) 
            }) 
     }) 
</script>

css

#hotTopic{width:445px;*width:422px; height:20px; overflow:hidden;float:left;border:1px solid #3e6388; margin-top:-2px;*margin-top:-1px;_margin-top:0px;}
.wrap{float: left;width:100000px;}
#talking,#scroll{float:left;}
#talking li,#scroll li{height:20px; color:#e9bb19;padding-left:10px;float:left; line-height:20px;}
#talking li a,#scroll li a{color:#e9bb19; font-family:"宋體";}

 

 

 

原博文

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.