我有一组定时图像,我想使用jQuery淡入其中

时间:2012-04-04 10:57:58

标签: jquery arrays image fadein fadeout

这是我的脚本,它按照预期的方式工作,但是通过使用jQuery淡入/淡出,我也希望在图像之间淡入淡出而不会对我的脚本进行太多更改。

<script language="JAVASCRIPT" type="text/javascript">

var ads = new Array();
    ads[1] = new Image ();
    ads[2] = new Image ();
    ads[3] = new Image ();
    ads[4] = new Image ();

        ads[1].src = "images/fender.jpg" ;
        ads[2].src = "images/gibson.jpg" ;
        ads[3].src = "images/marshall.jpg" ;
        ads[4].src = "images/laney.jpg" ;

var timing = new Array();
    timing[1] = 2500 ;
    timing[2] = 2500 ;
    timing[3] = 2500 ;
    timing[4] = 2500 ;

var sites = new Array();
    sites[1] = "http://www.fender.co.uk";
    sites[2] = "http://www2.gibson.com";
    sites[3] = "http://www.marshallamps.com";
    sites[4] = "http://www.laney.co.uk";

var adnumber = 0;
var totalAds = ads.length - 1;
var timerID = "";

function startBanner (){
    adnumber = 0;
    showAd();
    }   

function showAd() {
    if (document.images){
        if (document.myBanner.complete){
            adnumber++;
            (adnumber > totalAds) ? adnumber=1 : adnumber=adnumber;
            document.myBanner.src = ads[adnumber].src;
            }
            timerID = setTimeout("showAd()",timing[adnumber]);
        }
    }

function goSite(){
    clearTimeout(timerID);
    window.location.href = sites[adnumber];
    }
</script>

一些指导会很棒,谢谢,Finbar

1 个答案:

答案 0 :(得分:0)

This tutorial应该引导您完成一些jQuery基础知识。

同样$.each() method将帮助您遍历数组而不会丢失jQ-zen。