JS 纯JS幻灯片

来源:互联网 发布:json 中文乱码 编辑:程序博客网 时间:2024/06/11 02:44


JS 纯JS幻灯片


html

Java代码  收藏代码
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  5. <title>纯JS幻灯版</title>  
  6. <style type="text/css">  
  7. *{ margin:0; padding:0;}  
  8. #banner {width:1000px;text-align:left; background:#fff; margin:0 auto;}  
  9. #banner img{ display:block; float:left;}  
  10. .mainbox{ overflow:hidden; position:relative;}  
  11. .flashbox{ overflow:hidden; position:relative;}  
  12. .imagebox{ text-align:right;position:relative;z-index:999;}  
  13. .bitdiv{display:inline-block;width:18px;height:18px;margin:0 10px 10px 0px;cursor:pointer;float:right;}  
  14. .defimg{ background:url(styles/images/ppt_icon2.png);}  
  15. .curimg{background:url(styles/images/ppt_icon1.png);}  
  16. </style>  
  17. <script type="text/javascript" src="styles/js/ppt_ban.js"></script>  
  18. </head>  
  19. <body>  
  20. <div id="banner">  
  21.     <script>  
  22.      var box =new PPTBox();  
  23.      box.width = 1000//宽度  
  24.      box.height = 226;//高度  
  25.      box.autoplayer = 3;//自动播放间隔时间  
  26.      //box.add({"url":"图片地址","title":"悬浮标题","href":"链接地址"})  
  27.      box.add({"url":"styles/images/fck_04.jpg","href":"###","title":"悬浮提示标题1"});  
  28.      box.add({"url":"styles/images/fck_04.jpg","href":"###","title":"悬浮提示标题1"});  
  29.      box.add({"url":"styles/images/fck_04.jpg","href":"###","title":"悬浮提示标题1"});  
  30.      box.add({"url":"styles/images/fck_04.jpg","href":"###","title":"悬浮提示标题1"});  
  31.      box.show();  
  32.     </script>  
  33. </div>  
  34. </body>  
  35. </html>  

 

伦理片 http://www.dotdy.com/

Java代码  收藏代码
  1. function PPTBox()  
  2. {  
  3.     this.uid = PPTBoxHelper.getId();  
  4.     PPTBoxHelper.instance[this.uid] = this;  
  5.     this._$ = function(id){return document.getElementById(id);};  
  6.     this.width = 400;//宽度  
  7.     this.height = 300;//高度  
  8.     this.picWidth = 15;//小图宽度  
  9.     this.picHeight = 12;//小图高度  
  10.     this.autoplayer = 4;//自动播放间隔(秒)  
  11.     this.target = "_blank";  
  12.     this._box = [];  
  13.     this._curIndex = 0;  
  14. }  
  15. PPTBox.prototype =  
  16. {  
  17.     _createMainBox : function (){  
  18.         var flashBoxWidth = this.width * this._box.length;  
  19.         var html="<div id='"+this.uid+"_mainbox' class='mainbox'  style='width:"+(this.width)+"px;height:"+(this.height)+"px;'>";  
  20.         html += "<div id='"+this.uid+"_flashbox' class='flashbox' style='width:"+flashBoxWidth+"px;height:"+(this.height)+"px;'></div>";  
  21.         html += "<div id='"+this.uid+"_imagebox' class='imagebox' style='width:"+this.width+"px;height:"+(this.picHeight)+"px;top:-"+(this.picHeight+20)+"px;'></div>";  
  22.         html += "</div>";  
  23.         document.write(html);  
  24.     },  
  25.     _init : function (){  
  26.         var picstyle= "";  
  27.         var eventstr = "PPTBoxHelper.instance['"+this.uid+"']";  
  28.         var imageHTML="";  
  29.         var flashbox = "";  
  30.         for(var i=0;i<this._box.length;i++){  
  31.             var parame = this._box[i];  
  32.             flashbox += this.flashHTML(parame.url,this.width,this.height,i);  
  33.             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;  
  34.         }  
  35.         this._$(this.uid+"_flashbox").innerHTML = flashbox;  
  36.         this._$(this.uid+"_imagebox").innerHTML = imageHTML;  
  37.   
  38.     },  
  39.     _play : function(){  
  40.         clearInterval(this._autoplay);  
  41.         var idx = this._curIndex+1;  
  42.         if(idx>=this._box.length){idx=0;}  
  43.         this.changeIndex(idx);  
  44.         var eventstr = "PPTBoxHelper.instance['"+this.uid+"']._play()";  
  45.         this._autoplay = setInterval(eventstr,this.autoplayer*1000);  
  46.   
  47.     },  
  48.     flashHTML : function(url,width,height,idx) {  
  49.         var isFlash = url.substring(url.lastIndexOf('.')+1).toLowerCase()=="swf";  
  50.         var html = "";  
  51.         if(isFlash){  
  52.             html = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' "  
  53.             + "codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='"+width+"' height='"+height+"'>"  
  54.             + "<param name=\"movie\" value=\""+url+"\" />"  
  55.             + "<param name='quality' value='high' />"  
  56.             + "<param name='wmode' value='transparent'>"  
  57.             + "<embed src='"+url+"' quality='high' wmode='opaque' pluginspage='http://www.macromedia.com/go/getflashplayer'"  
  58.             +"  type='application/x-shockwave-flash' width="+width+" height='"+height+"'></embed>"  
  59.             +"  </object>";  
  60.         } else {  
  61.             var eventstr = "PPTBoxHelper.instance['"+this.uid+"']";  
  62.             var style = "";  
  63.             if(this._box[idx].href){  
  64.                 style = "cursor:pointer"  
  65.             }  
  66.             html="<img src='"+url+"' style='width:"+width+"px;height:"+height+"px;"+style+"' onclick = \""+eventstr+".clickPic("+idx+")\"/>";  
  67.         }  
  68.         return html;  
  69.     },  
  70.     changeIndex : function(idx){  
  71.         var parame = this._box[idx];  
  72.         moveElement(this.uid+"_flashbox",-(idx*this.width),1);  
  73.         var imgs = this._$(this.uid+"_imagebox").getElementsByTagName("div");  
  74.         imgs[this._box.length-1-this._curIndex].className = "bitdiv defimg";  
  75.         imgs[this._box.length-1-idx].className = "bitdiv curimg";  
  76.         this._curIndex = idx;  
  77.     },  
  78.     mouseoverPic:function(idx){  
  79.         this.changeIndex(idx);  
  80.         if(this.autoplayer>0){  
  81.            clearInterval(this._autoplay);  
  82.            var eventstr = "PPTBoxHelper.instance['"+this.uid+"']._play()";  
  83.            this._autoplay = setInterval(eventstr,this.autoplayer*1000);  
  84.         }  
  85.     },  
  86.     clickPic:function(idx){  
  87.         var parame = this._box[idx];  
  88.         if(parame.href&&parame.href!=""){  
  89.             window.open(parame.href,this.target);  
  90.         }  
  91.     },  
  92.     add:function (imgParam){  
  93.         this._box[this._box.length] = imgParam;  
  94.     },  
  95.     show : function () {  
  96.        this._createMainBox();  
  97.        this._init();  
  98.        if(this.autoplayer>0){  
  99.            var eventstr = "PPTBoxHelper.instance['"+this.uid+"']._play()";  
  100.            this._autoplay = setInterval(eventstr,this.autoplayer*1000);  
  101.        }  
  102.     }  
  103. }  
  104. var PPTBoxHelper =  
  105. {  
  106.     count: 0,  
  107.     instance: {},  
  108.     getId: function() { return '_ppt_box-' + (this.count++); }  
  109. };  
  110.   
  111. function moveElement(elementID,final_x,interval) {  
  112.   if (!document.getElementById) return false;  
  113.   if (!document.getElementById(elementID)) return false;  
  114.   var elem = document.getElementById(elementID);  
  115.   if (elem.movement) {  
  116.     clearTimeout(elem.movement);  
  117.   }  
  118.   if (!elem.style.left) {  
  119.     elem.style.left = "0px";  
  120.   }  
  121.   var xpos = parseInt(elem.style.left);  
  122.   if (xpos == final_x ) {  
  123.         return true;  
  124.   }  
  125.   if (xpos < final_x) {  
  126.     var dist = Math.ceil((final_x - xpos)/5);  
  127.     xpos = xpos + dist;  
  128.   }  
  129.   if (xpos > final_x) {  
  130.     var dist = Math.ceil((xpos - final_x)/5);  
  131.     xpos = xpos - dist;  
  132.   }  
  133.   elem.style.left = xpos + "px";  
  134.   var repeat = "moveElement('"+elementID+"',"+final_x+","+interval+")";  
  135.   elem.movement = setTimeout(repeat,interval);  
  136. }  

影音先锋电影 http://www.iskdy.com/  

效果图:

 

0 0
原创粉丝点击