国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

JS實(shí)現(xiàn)的幻燈片切換顯示效果

2019-11-20 09:03:26
字體:
供稿:網(wǎng)友

本文實(shí)例講述了JS實(shí)現(xiàn)的幻燈片切換顯示效果。分享給大家供大家參考,具體如下:

html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>純JS幻燈版</title><style type="text/css">*{ margin:0; padding:0;}#banner {width:1000px;text-align:left; background:#fff; margin:0 auto;}#banner img{ display:block; float:left;}.mainbox{ overflow:hidden; position:relative;}.flashbox{ overflow:hidden; position:relative;}.imagebox{ text-align:right;position:relative;z-index:999;}.bitdiv{display:inline-block;width:18px;height:18px;margin:0 10px 10px 0px;cursor:pointer;float:right;}.defimg{ background:url(styles/images/ppt_icon2.png);}.curimg{background:url(styles/images/ppt_icon1.png);}</style><script type="text/javascript" src="styles/js/ppt_ban.js"></script></head><body><div id="banner">  <script>   var box =new PPTBox();   box.width = 1000; //寬度   box.height = 226;//高度   box.autoplayer = 3;//自動播放間隔時間   //box.add({"url":"圖片地址","title":"懸浮標(biāo)題","href":"鏈接地址"})   box.add({"url":"styles/images/fck_04.jpg","href":"###","title":"懸浮提示標(biāo)題1"});   box.add({"url":"styles/images/fck_04.jpg","href":"###","title":"懸浮提示標(biāo)題1"});   box.add({"url":"styles/images/fck_04.jpg","href":"###","title":"懸浮提示標(biāo)題1"});   box.add({"url":"styles/images/fck_04.jpg","href":"###","title":"懸浮提示標(biāo)題1"});   box.show();  </script></div></body></html>

js:

function PPTBox(){  this.uid = PPTBoxHelper.getId();  PPTBoxHelper.instance[this.uid] = this;  this._$ = function(id){return document.getElementById(id);};  this.width = 400;//寬度  this.height = 300;//高度  this.picWidth = 15;//小圖寬度  this.picHeight = 12;//小圖高度  this.autoplayer = 4;//自動播放間隔(秒)  this.target = "_blank";  this._box = [];  this._curIndex = 0;}PPTBox.prototype ={  _createMainBox : function (){    var flashBoxWidth = this.width * this._box.length;    var html="<div id='"+this.uid+"_mainbox' class='mainbox' style='width:"+(this.width)+"px;height:"+(this.height)+"px;'>";    html += "<div id='"+this.uid+"_flashbox' class='flashbox' style='width:"+flashBoxWidth+"px;height:"+(this.height)+"px;'></div>";    html += "<div id='"+this.uid+"_imagebox' class='imagebox' style='width:"+this.width+"px;height:"+(this.picHeight)+"px;top:-"+(this.picHeight+20)+"px;'></div>";    html += "</div>";    document.write(html);  },  _init : function (){    var picstyle= "";    var eventstr = "PPTBoxHelper.instance['"+this.uid+"']";    var imageHTML="";    var flashbox = "";    for(var i=0;i<this._box.length;i++){      var parame = this._box[i];      flashbox += this.flashHTML(parame.url,this.width,this.height,i);      imageHTML ="<div class='bitdiv "+((i==0)?"curimg":"defimg")+"' title ="+parame.title+" src='bit01.gif' "+picstyle+" onclick = /""+eventstr+".clickPic("+i+")/" onmouseover=/""+eventstr+".mouseoverPic("+i+")/"></div>" + imageHTML;    }    this._$(this.uid+"_flashbox").innerHTML = flashbox;    this._$(this.uid+"_imagebox").innerHTML = imageHTML;  },  _play : function(){    clearInterval(this._autoplay);    var idx = this._curIndex+1;    if(idx>=this._box.length){idx=0;}    this.changeIndex(idx);    var eventstr = "PPTBoxHelper.instance['"+this.uid+"']._play()";    this._autoplay = setInterval(eventstr,this.autoplayer*1000);  },  flashHTML : function(url,width,height,idx) {    var isFlash = url.substring(url.lastIndexOf('.')+1).toLowerCase()=="swf";    var html = "";    if(isFlash){      html = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' "      + "codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='"+width+"' height='"+height+"'>"      + "<param name=/"movie/" value=/""+url+"/" />"      + "<param name='quality' value='high' />"      + "<param name='wmode' value='transparent'>"      + "<embed src='"+url+"' quality='high' wmode='opaque' pluginspage='http://www.macromedia.com/go/getflashplayer'"      +" type='application/x-shockwave-flash' width="+width+" height='"+height+"'></embed>"      +" </object>";    } else {      var eventstr = "PPTBoxHelper.instance['"+this.uid+"']";      var style = "";      if(this._box[idx].href){        style = "cursor:pointer"      }      html="<img src='"+url+"' style='width:"+width+"px;height:"+height+"px;"+style+"' onclick = /""+eventstr+".clickPic("+idx+")/"/>";    }    return html;  },  changeIndex : function(idx){    var parame = this._box[idx];    moveElement(this.uid+"_flashbox",-(idx*this.width),1);    var imgs = this._$(this.uid+"_imagebox").getElementsByTagName("div");    imgs[this._box.length-1-this._curIndex].className = "bitdiv defimg";    imgs[this._box.length-1-idx].className = "bitdiv curimg";    this._curIndex = idx;  },  mouseoverPic:function(idx){    this.changeIndex(idx);    if(this.autoplayer>0){      clearInterval(this._autoplay);      var eventstr = "PPTBoxHelper.instance['"+this.uid+"']._play()";      this._autoplay = setInterval(eventstr,this.autoplayer*1000);    }  },  clickPic:function(idx){    var parame = this._box[idx];    if(parame.href&¶me.href!=""){      window.open(parame.href,this.target);    }  },  add:function (imgParam){    this._box[this._box.length] = imgParam;  },  show : function () {    this._createMainBox();    this._init();    if(this.autoplayer>0){      var eventstr = "PPTBoxHelper.instance['"+this.uid+"']._play()";      this._autoplay = setInterval(eventstr,this.autoplayer*1000);    }  }}var PPTBoxHelper ={  count: 0,  instance: {},  getId: function() { return '_ppt_box-' + (this.count++); }};function moveElement(elementID,final_x,interval) { if (!document.getElementById) return false; if (!document.getElementById(elementID)) return false; var elem = document.getElementById(elementID); if (elem.movement) {  clearTimeout(elem.movement); } if (!elem.style.left) {  elem.style.left = "0px"; } var xpos = parseInt(elem.style.left); if (xpos == final_x ) {    return true; } if (xpos < final_x) {  var dist = Math.ceil((final_x - xpos)/5);  xpos = xpos + dist; } if (xpos > final_x) {  var dist = Math.ceil((xpos - final_x)/5);  xpos = xpos - dist; } elem.style.left = xpos + "px"; var repeat = "moveElement('"+elementID+"',"+final_x+","+interval+")"; elem.movement = setTimeout(repeat,interval);}

效果圖如下:

更多關(guān)于JavaScript相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《JavaScript切換特效與技巧總結(jié)》、《JavaScript查找算法技巧總結(jié)》、《JavaScript動畫特效與技巧匯總》、《JavaScript錯誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》及《JavaScript數(shù)學(xué)運(yùn)算用法總結(jié)

希望本文所述對大家JavaScript程序設(shè)計有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 方正县| 财经| 微博| 昌平区| 自贡市| 丰宁| 天气| 获嘉县| 文昌市| 苍溪县| 子长县| 五指山市| 汕尾市| 泰州市| 枣强县| 神农架林区| 云浮市| 吴堡县| 游戏| 体育| 新绛县| 高安市| 澄江县| 青铜峡市| 富裕县| 秦皇岛市| 平和县| 左权县| 延川县| 扶沟县| 鄱阳县| 怀安县| 邹平县| 英超| 忻城县| 马边| 铁岭县| 瑞安市| 原阳县| 白山市| 阜康市|