2013-12-17 96 views
1

我有一個div,其中某些控件在從數據庫獲取數據後動態添加。 它有點新聞細節將被添加。我只是想讓這個消息自動滾動,這是我通過javascript實現的。使用javascript停止mouseover上的動畫

現在,如果我想停止mouseover上的動畫並繼續mouseout,我該如何修改javascipt。

這是我的html頁面:

<section id="secbody" runat="server" style="position:absolute; background-color:dimgray; max-height:183px; min-height:183%;margin-top:14px;margin-left:545px;width:535px;"> 

     <div id="galheader" style="width:535px;" runat="server"> 
     <label id="Label1" style="color:White; position:absolute; font-size:20px; left:20px; height: 26px; width: 100%;" runat="server"> Upcoming Programs</label> 
</div> 

    <section id="secdetails" runat="server" style="font-family:'Palatino Linotype';color:white; min-width:500px;overflow-wrap:break-word;background-attachment:fixed;position:absolute;margin-top:25px;"></section> 
    </section>  

,這是我的javascript

<script type="text/javascript"> 

     $(document).ready(function(){ 
      function marqueePlay(){ 
       $("#secdetails").animate(
        { 
         top: $("#secbody").height() - $("#secdetails").height(), 
         opacity: 1 
        }, 4000, function(){ 
         $("#secdetails").css("top", 1); 
         $("#secdetails").css("opacity", 1); 
         marqueePlay(); 
        } 
       ); 
      } 
      marqueePlay(); 

}); 

    </script> 

我知道我們需要使用.stop功能,但不知道使用它的正確方法。

+0

你有沒有試過答案? –

+0

@RajaprabhuAravindasamy ..我還有一個問題..你能幫我嗎.. –

+0

是的,當然可以告訴我。 –

回答

2

可以使用.hover()函數來完成你的任務

嘗試,

$("#secdetails").hover(function(){ 
    $(this).stop(); //Stop the animation when mouse in 
}, 
function(){ 
    marqueePlay(); //Start the animation when mouse out 
}); 
1

這個怎麼樣?

function stopAnimation(){ 
    $("#secdetails").stop(); 
} 

<div id="secdetails" onmouseout="marqueePlay()" onmouseover="stopAnimation()"></div> 
+0

謝謝你的快速回復......但答案似乎是正確的,但我不知道它沒有工作..反正..謝謝你的努力.. :) –