图片/图形

随鼠标位置变化移动速度图片放大缩小特效

阿里云


这是一款使用纯 js 制作的炫酷随鼠标位置变化移动速度图片放大缩小展示特效。整个 js 代码短小精悍,100 多行代码即完成了令人惊叹的效果。

HTML 结构

  1. <div style="position:absolute;left:50%;top:50%">
  2.     <div style="position:absolute;width:720px;height:560px;left:-360px;top:-280px;background:#fff"></div>
  3.     <div style="position:absolute;left:-40px;top:-6px;color:#000;font-family:arial;font-size:0.9em">Loading...</div>
  4.     <div id="screen" style="position:absolute;width:640px;height:480px;left:-320px;top:-240px;overflow:hidden"></div>
  5. </div>
  6. <div id="images" style="visibility:hidden">
  7.     <img title="infinite" src="images/1.jpg">
  8.     <img title="yellow" src="images/2.jpg">
  9.     <img title="earth" src="images/3.jpg">
  10.     <img title="dream" src="images/4.jpg">
  11.     <img title="flowers" src="images/5.jpg">
  12. </div>
也想出现在这里?联系我们
创客主机

CSS 代码

css 代码如下,只是简单的定位一些元素和给出宽度和高度:

  1. html {overflow: hidden;}
  2. body {
  3.     background-image:-webkit-radial-gradient(circle at top right,#5596BC,#75BEC7);
  4.     background-image:-moz-radial-gradient(circle at top right,#5596BC,#75BEC7);
  5.     background-image:-o-radial-gradient(circle at top right,#5596BC,#75BEC7);
  6.     background-image:-ms-radial-gradient(circle at top right,#5596BC,#75BEC7);
  7.     background-image:radial-gradient(circle at top right,#5596BC,#75BEC7);
  8.     width: 100%;
  9.     height: 100%;
  10.     cursor: crosshair;
  11. }
  12. .spanSlide {
  13.     position: absolute;
  14.     background: #000;
  15.     font-size: 1px;
  16.     overflow: hidden;
  17. }
  18. .imgSlide {
  19.     position: absolute;
  20.     left: 5%;
  21.     top: 5%;
  22.     width: 90%;
  23.     height: 90%;
  24.     overflow: hidden;
  25. }
  26. .txtSlide {
  27.     position: absolute;
  28.     top: 5%;
  29.     left: 50px;
  30.     width:100%;
  31.     color:#FFF;
  32.     font-family: arial, helvetica, verdana, sans-serif;
  33.     font-weight: bold;
  34.     font-size:96px;
  35.     letter-spacing:12px;
  36.     filter: alpha(opacity=70);
  37.     -moz-opacity:0.7;
  38.     opacity:0.7;
  39. }

JAVASCRIPT

所有的 js 代码仅仅是下面的 73 行代码:

  1. var ym=0;
  2. var ny=0;
  3. createElement = function(container, type, param){
  4.     o=document.createElement(type);
  5.     for(var i in param)o[i]=param[i];
  6.     container.appendChild(o);
  7.     return o;
  8. }
  9. mooz = {
  10.     O:[],
  11.     /////////
  12.     mult:6,
  13.     nbI:5,
  14.     /////////
  15.     rwh:0,
  16.     imgsrc:0,
  17.     W:0,
  18.     H:0,
  19.     Xoom:function(N){
  20.         this.o = createElement(document.getElementById("screen"), "span", {
  21.             'className':'spanSlide'
  22.         });
  23.         img = createElement(this.o, "img", {
  24.             'className':"imgSlide",
  25.             'src':mooz.imgsrc[N%mooz.imgsrc.length].src
  26.         });
  27.         spa = createElement(this.o, "span", {
  28.             'className':"imgSlide"
  29.         });
  30.         txt = createElement(spa, "span", {
  31.             'className':"txtSlide",
  32.             'innerHTML':mooz.imgsrc[N%mooz.imgsrc.length].title
  33.         });
  34.         this.N = 10000+N;
  35.     },
  36.     mainloop:function(){
  37.         with(this){
  38.             for(i=0; i<mooz.nbi; i++)="" {="" o[i].n="" +="(ym-ny)/8000;" n="O[i].N%nbI;" ti="Math.pow(mult,N);" with(o[i].o.style){="" left="Math.round((W-(ti*rwh))/(W+ti)*(W*.5))+"px";" top="Math.round((H-ti)/(H+ti)*(H*.5))+"px";" zindex="Math.round(10000-ti*.1);" width="Math.round(ti*rwh)+"px";" height="Math.round(ti)+"px";" }="" settimeout("mooz.mainloop();",="" 16);="" },="" oigres:function(){="" with(this){="" w="parseInt(document.getElementById("screen").style.width);" h="parseInt(document.getElementById("screen").style.height);" imgsrc="document.getElementById("images").getElementsByTagName("img");" rwh="imgsrc[0].width/imgsrc[0].height;" for(var="" i="0;i<nbI;i++)" o[i]="new" xoom(i);="" mainloop();="" document.onmousemove="function(e){" if(window.event)="" e="window.event;" ym="(e.y" ||="" e.clienty);="" if(ym="" 2="">ny)ny=ym/2;
  39. }
  40. window.onload = function(){
  41.     ym = ny+50;
  42.     mooz.oigres();
  43. }

随鼠标位置变化移动速度图片放大缩小特效

已有 400 人购买
查看演示升级 VIP立刻购买

演示地址 下载地址
收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!