javascript 圖片自動輪換代碼

來源:互聯網
上載者:User

javascript 圖片自動輪換代碼

// JavaScript Document
var sPicArr = new Array();
var gIndex  = new Array();
var sid  = new Array();
var timeout = 6000;
var isIe = ('Microsoft Internet Explorer' == navigator.appName);
function initSlide(name,timeout1) {
 sPicArr[name] = new Array();
 gIndex[name]  = 0;
 sid[name] = null;
 if (timeout1) {
  timeout = timeout1;
 }
}
/*
content = new Array(圖片路徑,標題,URL);
*/
function initData(name, index, content) {
 sPicArr[name][index] = content;
 
}

function initFirst(name) {
 document.images[name + '_pic'].src = sPicArr[name][0][0];
 document.images[name + '_pic'].alt = sPicArr[name][0][1];
 $(name + '_picLink').href      = sPicArr[name][0][2];
 $(name + '_title').innerHTML     = sPicArr[name][0][1];
 $(name + '_title').href      = sPicArr[name][0][2];
}

function $(objName) {
 if(document.getElementById) {
  return eval('document.getElementById("' + objName + '")');
 } else if (document.layers) {
  return eval("document.layers['" + objName +"']");
 }else{
  return eval('document.all.' + objName);
 }
}
var plPic = new Image();
function SlidePic(name,index){
 gIndex[name] = index;

 if (isIe) {
  //document.images[name + '_pic'].filters.item(0).Transition = 12;
  document.images[name + '_pic'].filters.item(0).Apply();
 }

 document.images[name + '_pic'].src = sPicArr[name][index][0];
 document.images[name + '_pic'].alt = sPicArr[name][index][1];
 $(name + '_picLink').href      = sPicArr[name][index][2];
 $(name + '_title').innerHTML     = sPicArr[name][index][1];
 $(name + '_title').href      = sPicArr[name][index][2];

 if((index+1)<sPicArr[name].length) {
  plPic.src = sPicArr[name][index+1][0];//preload;
 }

 if (isIe) {
  document.images[name + '_pic'].filters.item(0).play();
 }
}

function NextPic(name) {
 gIndex[name] = ((gIndex[name]+1)>=sPicArr[name].length ? 0 : (gIndex[name]+1));
 SlidePic(name, gIndex[name]);
}

function PrevPic(name) {
 gIndex[name] = ((gIndex[name]-1)<0 ? (sPicArr[name].length-1) : (gIndex[name]-1));
 SlidePic(name, gIndex[name]);
}

function inislide(name) {
 if(sid[name]==null) {
  sid[name] = setInterval('NextPic("'+name+'")', timeout);
 }
}
function pauseslide(name) {
 clearInterval(sid[name]);
 sid[name] = null;
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.