JS实现的幻灯片切换显示效果

2022-01-14,,,

这篇文章主要介绍了JS实现的幻灯片切换显示效果,涉及javascript通过扩展实现针对页面元素的动态切换操作相关技巧,需要的朋友可以参考下

本文实例讲述了JS实现的幻灯片切换显示效果。分享给大家供大家参考,具体如下:

html:

   纯JS幻灯版 *{ 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-600);} .curimg{background:url(styles/images/ppt_icon1.png-600);}   

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=""; html += ""; html += ""; html += ""; 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){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 = "" + "" + "" + "" + "" +" "; } else { var eventstr = "PPTBoxHelper.instance['"+this.uid+"']"; var style = ""; if(this._box[idx].href){ style = "cursor:pointer" } html=""; } 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&&parame.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((xpos - final_x)/5); xpos = xpos - dist; } elem.style.left = xpos + "px"; var repeat = "moveElement('"+elementID+"',"+final_x+","+interval+")"; elem.movement = setTimeout(repeat,interval); } 

效果图如下:

更多关于JavaScript相关内容感兴趣的读者可查看本站专题:《JavaScript切换特效与技巧总结》、《JavaScript查找算法技巧总结》、《JavaScript动画特效与技巧汇总》、《JavaScript错误与调试技巧总结》、《JavaScript数据结构与算法技巧总结》及《JavaScript数学运算用法总结》

希望本文所述对大家JavaScript程序设计有所帮助。

以上就是JS实现的幻灯片切换显示效果的详细内容,更多请关注本站其它相关文章!

《JS实现的幻灯片切换显示效果.doc》

下载本文的Word格式文档,以方便收藏与打印。