0

以下代码可以在 IE 中停止幻灯片横幅,但在 Firefox 中不能暂停?请帮忙。

谢谢。

以下是我显示横幅的 javascript 代码:

var promotionTime;
var p=0;
var zone=0;

function changeBanner2(imgFile,imglink,altText){
//pause banner when mouseover
if((document.getElementById("promotionBanner").getAttribute("paused"))!=true)     {     
document.getElementById("promotionBanner").src=imgFile;
document.getElementById("promotionBanner").title=altText;
document.getElementById("bannerLink").href=imglink;
} }

function promotionBannerChanger(promotionImg,promotionLink,promotionAlt,num){
if(zone!=num){
    p=0;
    zone=num;
}

//set attribute to pause banner when mouseover
document.getElementById("promotionBanner").onmouseover =
                     function() { this.setAttribute("paused", true);}
document.getElementById("promotionBanner").onmouseout = 
                     function() { this.removeAttribute("paused");}

changeBanner2(promotionImg[p],promotionLink[p],promotionAlt[p]);
p++;
if(p>=promotionImg.length){
    p=0;
}
clearTimeout(promotionTime);
if(num==1)
    promotionTime=setTimeout("promotionBannerChanger(promotionImage1,promotionLink1,promotionAlt1,'1')",2000);
else if(num==2)
    promotionTime=setTimeout("promotionBannerChanger(promotionImage2,promotionLink2,promotionAlt2,'2')",2000);
else if(num==3)
    promotionTime=setTimeout("promotionBannerChanger(promotionImage3,promotionLink3,promotionAlt3,'3')",2000); }

ASP 代码:

            <td width="480" >
            <div id="banner" oonmouseover="paused=true;" onmouseout="paused=false;">
                    <a id="bannerLink" href="archive.htm"><img title="Hot Topic" src=./promotion/1/en/c1Lagge.GIF id="promotionBanner" width="480" height="252"  border="0"></a>
            </div>
                </td>
            </table>
4

3 回答 3

0

要清除clearTimeout()方法,您需要传递setTimeout()引用变量。在您的情况下,它将是“promotionTime”。

例如clearTimeout(setTimeout_variable)。在你的情况下,`clearTimeout(promotionTime

ps 你可以在http://www.w3schools.com/js/js_timing.asp查看 w3schools.com 链接

代码示例:

elements = document.getElementById('promotionBanner');
elements.onmouseover = function (promotionTime) {
    clearTimeout(promotionTime);
}
于 2011-07-19T02:42:32.533 回答
0
document.getElementById("promotionBanner").onmouseover =
                         function() { this.setAttribute("paused", true); };
document.getElementById("promotionBanner").onmouseout = 
                         function() { this.removeAttribute("paused"); };


function changeBanner2(imgFile,imglink,altText){
    if(document.getElementById("promotionBanner").getAttribute("paused")) {
        document.getElementById("promotionBanner").src=imgFile;
        document.getElementById("promotionBanner").title=altText;
        document.getElementById("bannerLink").href=imglink;
    }
}

基本上,在悬停时,您将“暂停”属性添加到promotionBanner,如果那是相关元素。如果超时功能在“暂停”属性处于活动状态时运行,请不要推进横幅。您可能还想从 changeBanner2 返回一个真/假值,以确定您是否推进计数器。这样,当鼠标离开并且横幅再次启动时,您将不会跳过图像。

于 2011-07-19T02:48:55.680 回答
0
    <!-- Start WOWSlider.com BODY section --> <!-- add to the <body> of your page -->
<div id="wowslider-container_fairy_tale">
<div class="ws_images_fairy_tale"><ul>
    <li><img src="images/fairy%20tale/1.jpg" id="Img1"/></li>
    <li><img src="images/fairy%20tale/2.jpg" id="Img2"/></li>
    <li><img src="images/fairy%20tale/3.jpg" alt="3" title="3" id="Img2"/></li>
    <li><img src="images/fairy%20tale/4.jpg" alt="4" title="4" id="Img3"/></li>

</ul></div>

<div class="ws_shadow"></div>
</div>  
<script type="text/javascript" src="fairy_tale/js/wowslider.js"></script>
<script type="text/javascript" src="fairy_tale/js/script.js"></script>
<!-- End WOWSlider.com BODY section -->[enter link description here][1]
于 2015-04-17T06:04:41.040 回答