Javascript应用--震撼的图片展示效果(图片换成你的图片名就可以运行了)

Code:
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">  
  2. <html>  
  3. <head>  
  4. <title>1</title>  
  5. <meta http-equiv="imagetoolbar" content="no">  
  6. <style type="text/css">  
  7.     html {   
  8.         overflow: hidden;   
  9.     }   
  10.     body {   
  11.         margin: 0px;   
  12.         padding: 0px;   
  13.         background: #000;   
  14.         width: 100%;   
  15.         height: 100%;   
  16.     }   
  17.     #imageFlow {   
  18.         position: absolute;   
  19.         width: 100%;   
  20.         height: 80%;   
  21.         left: 0%;   
  22.         top: 10%;   
  23.         background: #000;   
  24.     }   
  25.     #imageFlow .diapo {   
  26.         position: absolute;   
  27.         left: -1000px;   
  28.         cursor: pointer;   
  29.         -ms-interpolation-mode: nearest-neighbor;   
  30.     }   
  31.     #imageFlow .link {   
  32.         border: dotted #fff 1px;   
  33.         margin-left: -1px;   
  34.         margin-bottom: -1px;   
  35.     }   
  36.     #imageFlow .bank {   
  37.         visibility: hidden;   
  38.     }   
  39.     #imageFlow .top {   
  40.         position: absolute;   
  41.         width: 100%;   
  42.         height: 40%;   
  43.         background: #181818;   
  44.     }   
  45.     #imageFlow .text {   
  46.         position: absolute;   
  47.         left: 0px;   
  48.         width: 100%;   
  49.         bottom: 16%;   
  50.         text-align: center;   
  51.         color: #FFF;   
  52.         font-family: verdana, arial, Helvetica, sans-serif;   
  53.         z-index: 1000;   
  54.     }   
  55.     #imageFlow .title {   
  56.         font-size: 0.9em;   
  57.         font-weight: bold;   
  58.     }   
  59.     #imageFlow .legend {   
  60.         font-size: 0.8em;   
  61.     }   
  62.     #imageFlow .scrollbar {   
  63.         position: absolute;   
  64.         left: 10%;   
  65.         bottom: 10%;   
  66.         width: 80%;   
  67.         height: 16px;   
  68.         z-index: 1000;   
  69.     }   
  70.     #imageFlow .track {   
  71.         position: absolute;   
  72.         left: 1%;   
  73.         width: 98%;   
  74.         height: 16px;   
  75.         filter: alpha(opacity=30);   
  76.         opacity: 0.3;   
  77.     }   
  78.     #imageFlow .arrow-left {   
  79.         position: absolute;   
  80.     }   
  81.     #imageFlow .arrow-right {   
  82.         position: absolute;   
  83.         right: 0px;   
  84.     }   
  85.     #imageFlow .bar {   
  86.         position: absolute;   
  87.         height: 16px;   
  88.         left: 25px;   
  89.     }   
  90. </style>  
  91.   
  92. <script type="text/javascript">  
  93.   
  94. var imf = function () {   
  95.     var lf = 0;   
  96.     var instances = [];   
  97.     function getElementsByClass (object, tag, className) {   
  98.         var o = object.getElementsByTagName(tag);   
  99.         for ( var i = 0n = o.length, ret = []; i < n; i++)   
  100.             if (o[i].className == className) ret.push(o[i]);   
  101.         if (ret.length == 1) retret = ret[0];   
  102.         return ret;   
  103.     }   
  104.     function addEvent (o, e, f) {   
  105.         if (window.addEventListener) o.addEventListener(e, f, false);   
  106.         else if (window.attachEvent) r = o.attachEvent('on' + e, f);   
  107.     }   
  108.     function createReflexion (cont, img) {   
  109.         var flx = false;   
  110.         if (document.createElement("canvas").getContext) {   
  111.             flx = document.createElement("canvas");   
  112.             flx.width = img.width;   
  113.             flx.height = img.height;   
  114.             var context = flx.getContext("2d");   
  115.             context.translate(0, img.height);   
  116.             context.scale(1, -1);   
  117.             context.drawImage(img, 0, 0, img.width, img.height);   
  118.             context.globalCompositeOperation = "destination-out";   
  119.             var gradient = context.createLinearGradient(0, 0, 0, img.height * 2);   
  120.             gradient.addColorStop(1, "rgba(255, 255, 255, 0)");   
  121.             gradient.addColorStop(0, "rgba(255, 255, 255, 1)");   
  122.             context.fillStyle = gradient;   
  123.             context.fillRect(0, 0, img.width, img.height * 2);   
  124.         } else {   
  125.             /* ---- DXImageTransform ---- */   
  126.             flx     = document.createElement('img');   
  127.             flx.src = img.src;   
  128.             flx.style.filter = 'flipv progid:DXImageTransform.Microsoft.Alpha(' +   
  129.                                'opacity=50style=1finishOpacity=0startx=0starty=0finishx=0finishy=' +   
  130.                                (img.height * .25) + ')';   
  131.         }   
  132.         /* ---- insert Reflexion ---- */   
  133.         flx.style.position = 'absolute';   
  134.         flx.style.left     = '-1000px';   
  135.         cont.appendChild(flx);   
  136.         return flx;   
  137.     }   
  138.     /*  ==== ImageFlow Constructor ====  */   
  139.     function ImageFlow(oCont, size, zoom, border) {   
  140.         this.diapos     = [];   
  141.         this.scr        = false;   
  142.         this.size       = size;   
  143.         this.zoom       = zoom;   
  144.         this.bdw        = border;   
  145.         this.oCont      = oCont;   
  146.         this.oc         = document.getElementById(oCont);   
  147.         this.scrollbar  = getElementsByClass(this.oc,   'div', 'scrollbar');   
  148.         this.text       = getElementsByClass(this.oc,   'div', 'text');   
  149.         this.title      = getElementsByClass(this.text, 'div', 'title');   
  150.         this.legend     = getElementsByClass(this.text, 'div', 'legend');   
  151.         this.bar        = getElementsByClass(this.oc,   'img', 'bar');   
  152.         this.arL        = getElementsByClass(this.oc,   'img', 'arrow-left');   
  153.         this.arR        = getElementsByClass(this.oc,   'img', 'arrow-right');   
  154.         thisthis.bw         = this.bar.width;   
  155.         thisthis.alw        = this.arL.width - 5;   
  156.         thisthis.arw        = this.arR.width - 5;   
  157.         thisthis.bar.parent = this.oc.parent  = this;   
  158.         thisthis.arL.parent = this.arR.parent = this;   
  159.         thisthis.view       = this.back       = -1;   
  160.         this.resize();   
  161.         this.oc.onselectstart = function () { return false; }   
  162.         /* ---- create images ---- */   
  163.         var img   = getElementsByClass(this.oc, 'div', 'bank').getElementsByTagName('a');   
  164.         this.NF = img.length;   
  165.         for (var i = 0, o; o = img[i]; i++) {   
  166.             this.diapos[i] = new Diapo(this, i,   
  167.                                         o.rel,   
  168.                                         o.title || '- ' + i + ' -',   
  169.                                         o.innerHTML || o.rel,   
  170.                                         o.href || '',   
  171.                                         o.target || '_self'   
  172.             );   
  173.         }   
  174.         /* ==== add mouse wheel events ==== */   
  175.         if (window.addEventListener)   
  176.             this.oc.addEventListener('DOMMouseScroll', function(e) {   
  177.                 this.parent.scroll(-e.detail);   
  178.             }, false);   
  179.         else this.oc.onmousewheel = function () {   
  180.             this.parent.scroll(event.wheelDelta);   
  181.         }   
  182.         /* ==== scrollbar drag N drop ==== */   
  183.         this.bar.onmousedown = function (e) {   
  184.             if (!e) e = window.event;   
  185.             var scl = e.screenX - this.offsetLeft;   
  186.             var self = this.parent;   
  187.             /* ---- move bar ---- */   
  188.             this.parent.oc.onmousemove = function (e) {   
  189.                 if (!e) e = window.event;   
  190.                 self.bar.style.left = Math.round(Math.min((self.ws - self.arw - self.bw), Math.max(self.alw, e.screenX - scl))) + 'px';   
  191.                 self.view = Math.round(((e.screenX - scl) ) / (self.ws - self.alw - self.arw - self.bw) * self.NF);   
  192.                 if (self.view != self.back) self.calc();   
  193.                 return false;   
  194.             }   
  195.             /* ---- release scrollbar ---- */   
  196.             this.parent.oc.onmouseup = function (e) {   
  197.                 self.oc.onmousemove = null;   
  198.                 return false;   
  199.             }   
  200.             return false;   
  201.         }   
  202.         /* ==== right arrow ==== */   
  203.         thisthis.arR.onclick = this.arR.ondblclick = function () {   
  204.             if (this.parent.view < this.parent.NF - 1)   
  205.                 this.parent.calc(1);   
  206.         }   
  207.         /* ==== Left arrow ==== */   
  208.         thisthis.arL.onclick = this.arL.ondblclick = function () {   
  209.             if (this.parent.view > 0)   
  210.                 this.parent.calc(-1);   
  211.         }   
  212.     }   
  213.     /*  ==== ImageFlow prototype ====  */   
  214.     ImageFlow.prototype = {   
  215.         /* ==== targets ==== */   
  216.         calc : function (inc) {   
  217.             if (inc) this.view += inc;   
  218.             var tw = 0;   
  219.             var lw = 0;   
  220.             var o = this.diapos[this.view];   
  221.             if (o && o.loaded) {   
  222.                 /* ---- reset ---- */   
  223.                 var ob = this.diapos[this.back];   
  224.                 if (ob && ob != o) {   
  225.                     ob.img.className = 'diapo';   
  226.                     ob.z1 = 1;   
  227.                 }   
  228.                 /* ---- update legend ---- */   
  229.                 this.title.replaceChild(document.createTextNode(o.title), this.title.firstChild);   
  230.                 this.legend.replaceChild(document.createTextNode(o.text), this.legend.firstChild);   
  231.                 /* ---- update hyperlink ---- */   
  232.                 if (o.url) {   
  233.                     o.img.className = 'diapo link';   
  234.                     window.status = 'hyperlink: ' + o.url;   
  235.                 } else {   
  236.                     o.img.className = 'diapo';   
  237.                     window.status = '';   
  238.                 }   
  239.                 /* ---- calculate target sizes & positions ---- */   
  240.                 o.w1 = Math.min(o.iw, this.wh * .5) * o.z1;   
  241.                 var x0 = o.x1 = (this.wh * .5) - (o.w1 * .5);   
  242.                 var x = x0 + o.w1 + this.bdw;   
  243.                 for (var i = this.view + 1, o; o = this.diapos[i]; i++) {   
  244.                     if (o.loaded) {   
  245.                         o.x1 = x;   
  246.                         o.w1 = (this.ht / o.r) * this.size;   
  247.                         x   += o.w1 + this.bdw;   
  248.                         tw  += o.w1 + this.bdw;   
  249.                     }   
  250.                 }   
  251.                 x = x0 - this.bdw;   
  252.                 for (var i = this.view - 1, o; o = this.diapos[i]; i--) {   
  253.                     if (o.loaded) {   
  254.                         o.w1 = (this.ht / o.r) * this.size;   
  255.                         o.x1 = x - o.w1;   
  256.                         x   -o.w1 + this.bdw;   
  257.                         tw  += o.w1 + this.bdw;   
  258.                         lw  += o.w1 + this.bdw;   
  259.                     }   
  260.                 }   
  261.                 /* ---- move scrollbar ---- */   
  262.                 if (!this.scr && tw) {   
  263.                     var r = (this.ws - this.alw - this.arw - this.bw) / tw;   
  264.                     this.bar.style.left = Math.round(this.alw + lw * r) + 'px';   
  265.                 }   
  266.                 /* ---- save preview view ---- */   
  267.                 thisthis.back = this.view;   
  268.             }   
  269.         },   
  270.         /* ==== mousewheel scrolling ==== */   
  271.         scroll : function (sc) {   
  272.             if (sc < 0) {   
  273.                 if (this.view < this.NF - 1) this.calc(1);   
  274.             } else {   
  275.                 if (this.view > 0) this.calc(-1);   
  276.             }   
  277.         },   
  278.         /* ==== resize  ==== */   
  279.         resize : function () {   
  280.             thisthis.wh = this.oc.clientWidth;   
  281.             thisthis.ht = this.oc.clientHeight;   
  282.             thisthis.ws = this.scrollbar.offsetWidth;   
  283.             this.calc();   
  284.             this.run(true);   
  285.         },   
  286.         /* ==== move all images  ==== */   
  287.         run : function (res) {   
  288.             var i = this.NF;   
  289.             while (i--) this.diapos[i].move(res);   
  290.         }   
  291.     }   
  292.     /*  ==== Diapo Constructor ====  */   
  293.     Diapo = function (parent, N, src, title, text, url, target) {   
  294.         this.parent        = parent;   
  295.         this.loaded        = false;   
  296.         this.title         = title;   
  297.         this.text          = text;   
  298.         this.url           = url;   
  299.         this.target        = target;   
  300.         this.N             = N;   
  301.         this.img           = document.createElement('img');   
  302.         this.img.src       = src;   
  303.         thisthis.img.parent    = this;   
  304.         this.img.className = 'diapo';   
  305.         thisthis.x0            = this.parent.oc.clientWidth;   
  306.         thisthis.x1            = this.x0;   
  307.         this.w0            = 0;   
  308.         this.w1            = 0;   
  309.         this.z1            = 1;   
  310.         thisthis.img.parent    = this;   
  311.         this.img.onclick   = function() { this.parent.click(); }   
  312.         this.parent.oc.appendChild(this.img);   
  313.         /* ---- display external link ---- */   
  314.         if (url) {   
  315.             this.img.onmouseover = function () { this.className = 'diapo link'; }   
  316.             this.img.onmouseout  = function () { this.className = 'diapo'; }   
  317.         }   
  318.     }   
  319.     /*  ==== Diapo prototype ====  */   
  320.     Diapo.prototype = {   
  321.         /* ==== HTML rendering ==== */   
  322.         move : function (res) {   
  323.             if (this.loaded) {   
  324.                 var sx = this.x1 - this.x0;   
  325.                 var sw = this.w1 - this.w0;   
  326.                 if (Math.abs(sx) > 2 || Math.abs(sw) > 2 || res) {   
  327.                     /* ---- paint only when moving ---- */   
  328.                     this.x0 += sx * .1;   
  329.                     this.w0 += sw * .1;   
  330.                     if (this.x0 < this.parent.wh && this.x0 + this.w0 > 0) {   
  331.                         /* ---- paint only visible images ---- */   
  332.                         this.visible = true;   
  333.                         var o = this.img.style;   
  334.                         var h = this.w0 * this.r;   
  335.                         /* ---- diapo ---- */   
  336.                         o.left   = Math.round(this.x0) + 'px';   
  337.                         o.bottom = Math.floor(this.parent.ht * .25) + 'px';   
  338.                         o.width  = Math.round(this.w0) + 'px';   
  339.                         o.height = Math.round(h) + 'px';   
  340.                         /* ---- reflexion ---- */   
  341.                         if (this.flx) {   
  342.                             var o = this.flx.style;   
  343.                             o.left   = Math.round(this.x0) + 'px';   
  344.                             o.top    = Math.ceil(this.parent.ht * .75 + 1) + 'px';   
  345.                             o.width  = Math.round(this.w0) + 'px';   
  346.                             o.height = Math.round(h) + 'px';   
  347.                         }   
  348.                     } else {   
  349.                         /* ---- disable invisible images ---- */   
  350.                         if (this.visible) {   
  351.                             this.visible = false;   
  352.                             this.img.style.width = '0px';   
  353.                             if (this.flx) this.flx.style.width = '0px';   
  354.                         }   
  355.                     }   
  356.                 }   
  357.             } else {   
  358.                 /* ==== image onload ==== */   
  359.                 if (this.img.complete && this.img.width) {   
  360.                     /* ---- get size image ---- */   
  361.                     thisthis.iw     = this.img.width;   
  362.                     thisthis.ih     = this.img.height;   
  363.                     thisthis.r      = this.ih / this.iw;   
  364.                     this.loaded = true;   
  365.                     /* ---- create reflexion ---- */   
  366.                     this.flx    = createReflexion(this.parent.oc, this.img);   
  367.                     if (this.parent.view < 0thisthis.parent.view = this.N;   
  368.                     this.parent.calc();   
  369.                 }   
  370.             }   
  371.         },   
  372.         /* ==== diapo onclick ==== */   
  373.         click : function () {   
  374.             if (this.parent.view == this.N) {   
  375.                 /* ---- click on zoomed diapo ---- */   
  376.                 if (this.url) {   
  377.                     /* ---- open hyperlink ---- */   
  378.                     window.open(this.url, this.target);   
  379.                 } else {   
  380.                     /* ---- zoom in/out ---- */   
  381.                     thisthis.z1 = this.z1 == 1 ? this.parent.zoom : 1;   
  382.                     this.parent.calc();   
  383.                 }   
  384.             } else {   
  385.                 /* ---- select diapo ---- */   
  386.                 thisthis.parent.view = this.N;   
  387.                 this.parent.calc();   
  388.             }   
  389.             return false;   
  390.         }   
  391.     }   
  392.     /*  ==== public methods ====  */   
  393.     return {   
  394.         /* ==== initialize script ==== */   
  395.         create : function (div, size, zoom, border) {   
  396.             /* ---- instanciate imageFlow ---- */   
  397.             var load = function () {   
  398.                 var loaded = false;   
  399.                 var i = instances.length;   
  400.                 while (i--) if (instances[i].oCont == div) loaded = true;   
  401.                 if (!loaded) {   
  402.                     /* ---- push new imageFlow instance ---- */   
  403.                     instances.push(   
  404.                         new ImageFlow(div, size, zoom, border)   
  405.                     );   
  406.                     /* ---- init script (once) ---- */   
  407.                     if (!imf.initialized) {   
  408.                         imf.initialized = true;   
  409.                         /* ---- window resize event ---- */   
  410.                         addEvent(window, 'resize', function () {   
  411.                             var i = instances.length;   
  412.                             while (i--) instances[i].resize();   
  413.                         });   
  414.                         /* ---- stop drag N drop ---- */   
  415.                         addEvent(document.getElementById(div), 'mouseout', function (e) {   
  416.                             if (!e) e = window.event;   
  417.                             var tg = e.relatedTarget || e.toElement;   
  418.                             if (tg && tg.tagName == 'HTML') {   
  419.                                 var i = instances.length;   
  420.                                 while (i--) instances[i].oc.onmousemove = null;   
  421.                             }   
  422.                             return false;   
  423.                         });   
  424.                         /* ---- set interval loop ---- */   
  425.                         setInterval(function () {   
  426.                             var i = instances.length;   
  427.                             while (i--) instances[i].run();   
  428.                         }, 16);   
  429.                     }   
  430.                 }   
  431.             }   
  432.             /* ---- window onload event ---- */   
  433.             addEvent(window, 'load', function () { load(); });   
  434.         }   
  435.     }   
  436. }();   
  437.   
  438. /* ==== create imageFlow ==== */   
  439. //          div ID    , size, zoom, border   
  440. imf.create("imageFlow", 0.15, 1.5, 10);   
  441.   
  442. </script>  
  443. </head>  
  444.   
  445. <body>  
  446.     <div id="imageFlow">  
  447.         <div class="top"></div>  
  448.         <div class="bank">  
  449.             <a rel="ct37.jpg" title="Myselves" href="http://www.design-studio.cn/">My identity lies in not knowing who I am</a>  
  450.             <a rel="ct60.jpg" title="Discoveries" href="http://www.design-studio.cn/">...are made by not following instructions</a>  
  451.             <a rel="sf53.jpg" title="Nothing" href="http://www.design-studio.cn/">...can come between us</a>  
  452.             <a rel="sf48.jpg" title="New life" href="http://www.design-studio.cn/">Here you come!</a>  
  453.             <a rel="ct81.jpg" title="Optimists" href="http://www.design-studio.cn/">They don't know all the facts yet</a>  
  454.             <a rel="ct134.jpg" title="Empathy" href="http://www.design-studio.cn/">Emotional intimacy</a>  
  455.             <a rel="ct41.jpg" title="Much work" href="http://www.design-studio.cn/">...remains to be done before we can announce our total failure to make any progress</a>  
  456.             <a rel="ct75.jpg" title="System error" href="http://www.design-studio.cn/">Errare Programma Est</a>  
  457.             <a rel="bl201.jpg" title="Nonexistance" href="http://www.design-studio.cn/">There's no such thing</a>  
  458.             <a rel="ct137.jpg" title="Inside" href="http://www.design-studio.cn/">I抦 now trapped, without hope of escape or rescue</a>  
  459.             <a rel="ct65.jpg" title="E-Slaves" href="http://www.design-studio.cn/">The World is flat</a>  
  460.             <a rel="or105.jpg" title="l0v3" href="http://www.design-studio.cn/">1 l0v3 j00 - f0r3v3r</a>  
  461.             <a rel="ct139.jpg" title="T minus zero" href="http://www.design-studio.cn/">111 111 111 x 111 111 111 = 12345678987654321</a>  
  462.             <a rel="ct27.jpg" title="The End" href="http://www.design-studio.cn/">...has not been written yet</a>  
  463.         </div>  
  464.   
  465.         <div class="text">  
  466.             <div class="title">Loading</div>  
  467.             <div class="legend">Please wait...</div>  
  468.         </div>  
  469.         <div class="scrollbar">  
  470.             <img class="track" src="sb.gif" alt="">  
  471.             <img class="arrow-left" src="sl.gif" alt="">  
  472.             <img class="arrow-right" src="sr.gif" alt="">  
  473.             <img class="bar" src="sc.gif" alt="">  
  474.         </div>  
  475.     </div>  
  476. </body>  
  477. </html>  
  478.   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值