代码简介:

JavaScript 算法生成弹性透明的图片放大效果,代码值得看一下哦,弹性和缓冲是一个意思,JS缓冲效果在网页中使用很频繁,使用缓冲技术可以制作出超多的精美特效来。

代码内容:

View Code

< html >
< head >
< title > JavaScript弹性透明的图片放大代码_网页代码站(www.webdm.cn) </ title >
< style type = " text/css " >
    html {
        overflow: hidden;
    }

body {
        margin: 0px;
        padding: 0px;
        background: # 000 ;
        position: absolute;
        cursor: crosshair;
    }

#diapoContainer {
        position: absolute;
        left:  10 % ;
        top:  10 % ;
        width:  80 % ;
        height:  80 % ;
        background: # 222 ;
        overflow: hidden;
    }

.imgDC {
        position: absolute;
        cursor: pointer;
        border: # 000  solid 2px;
        filter: alpha(opacity = 90 );
        opacity:  0.9 ;
        visibility: hidden;
    }

.spaDC {
        position: absolute;
        filter: alpha(opacity = 20 );
        opacity:  0.2 ;
        background: # 000 ;
        visibility: hidden;
    }

.imgsrc {
        position: absolute;
        width: 120px;
        height: 67px;
        visibility: hidden;
        margin:  4 % ;
    }

#bkgcaption {
        position: absolute;
        bottom: 0px;
        left: 0px;
        width:  100 % ;
        height:  6 % ;
        background:#1a1a1a;
    }
    #caption {
        position: absolute;
        font - family: arial, helvetica, verdana, sans - serif;
        white - space: nowrap;
        color: #fff;
        bottom: 0px;
        width:  100 % ;
        left:  - 10000px;
        text - align: center;
    }

</ style >
< script type = " text/javascript " >
var xm;
var ym;
document.onmousemove  =  function(e){
     if (window. event ) e = window. event ;
    xm  =  (e.x  ||  e.clientX);
    ym  =  (e.y  ||  e.clientY);
}

function resize() {
     if (diapo)diapo.resize();
}
onresize  =  resize;

setOpacity  =  function(o, alpha){
     if (o.filters)o.filters.alpha.opacity  =  alpha  *   100 ;  else  o.style.opacity  =  alpha;
}
diapo  =  {
    O : [],
    DC :  0 ,
    img :  0 ,
    txt :  0 ,
    N :  0 ,
    xm :  0 ,
    ym :  0 ,
    nx :  0 ,
    ny :  0 ,
    nw :  0 ,
    nh :  0 ,
    rs :  0 ,
    rsB :  0 ,
    zo :  0 ,
    tx_pos :  0 ,
    tx_var :  0 ,
    tx_target :  0 ,
    attraction :  2 ,
    acceleration : . 9 ,
    dampening : . 1 ,
    zoomOver :  2 ,
    zoomClick :  6 ,
    transparency : . 8 ,
    font_size:  18 ,
    resize : function(){
        with( this ){
            nx  =  DC.offsetLeft;
            ny  =  DC.offsetTop;
            nw  =  DC.offsetWidth;
            nh  =  DC.offsetHeight;
            txt.style.fontSize  =  Math.round(nh  /  font_size)  +   " px " ;
             if (Math.abs(rs - rsB) < 100 )  for (var i = 0 ; i < N; i ++ ) O[i].resize();
            rsB  =  rs;
        }
    },

CDiapo : function(o){
         this .o         =  o;
         this .x_pos     =   this .y_pos     =   0 ;
         this .x_origin  =   this .y_origin  =   0 ;
         this .x_var     =   this .y_var     =   0 ;
         this .x_target  =   this .y_target  =   0 ;
         this .w_pos     =   this .h_pos     =   0 ;
         this .w_origin  =   this .h_origin  =   0 ;
         this .w_var     =   this .h_var     =   0 ;
         this .w_target  =   this .h_target  =   0 ;
         this .over      =   false ;
         this .click     =   false ;
         this .spa  =  document.createElement( " span " );
         this .spa.className  =   " spaDC " ;
        diapo.DC.appendChild( this .spa);
         this .img  =  document.createElement( " img " );
         this .img.className  =   " imgDC " ;
         this .img.src  =  o.src;
         this .img.O  =   this ;
        diapo.DC.appendChild( this .img);
        setOpacity( this .img, diapo.transparency);
         this .img.onselectstart  =   new  Function( " return false; " );
         this .img.ondrag  =   new  Function( " return false; " );
         this .img.onmouseover  =  function(){
            diapo.tx_target = 0 ;
            diapo.txt.innerHTML = this .O.o.alt;
             this .O.over = true ;
            setOpacity( this , this .O.click ? diapo.transparency: 1 );
        }
         this .img.onmouseout  =  function(){
            diapo.tx_target =- diapo.nw;
             this .O.over = false ;
            setOpacity( this ,diapo.transparency);
        }
         this .img.onclick  =  function() {
             if ( ! this .O.click){
                 if (diapo.zo  &&  diapo.zo  !=   this ) diapo.zo.onclick();
                 this .O.click  =   true ;
                 this .O.x_origin  =  (diapo.nw  -  ( this .O.w_origin  *  diapo.zoomClick))  /   2 ;
                 this .O.y_origin  =  (diapo.nh  -  ( this .O.h_origin  *  diapo.zoomClick))  /   2 ;
                diapo.zo  =   this ;
                setOpacity( this ,diapo.transparency);
            }  else  {
                 this .O.click  =   false ;
                 this .O.over  =   false ;
                 this .O.resize();
                diapo.zo  =   0 ;
            }
        }
         this .resize  =  function (){
            with ( this ) {
                x_origin  =  o.offsetLeft;
                y_origin  =  o.offsetTop;
                w_origin  =  o.offsetWidth;
                h_origin  =  o.offsetHeight;
            }
        }

this .position  =  function (){
            with ( this ) {
                w_target  =  w_origin;
                h_target  =  h_origin;
                 if (over){
                    w_target  =  w_origin  *  diapo.zoomOver;
                    h_target  =  h_origin  *  diapo.zoomOver;
                    x_target  =  diapo.xm  -  w_pos  /   2   -  (diapo.xm  -  (x_origin  +  w_pos  /   2 ))  /  (diapo.attraction * (click ? 10 : 1 ));
                    y_target  =  diapo.ym  -  h_pos  /   2   -  (diapo.ym  -  (y_origin  +  h_pos  /   2 ))  /  (diapo.attraction * (click ? 10 : 1 ));
                }  else  {
                    x_target  =  x_origin;
                    y_target  =  y_origin;
                }
                 if (click){
                    w_target  =  w_origin  *  diapo.zoomClick;
                    h_target  =  h_origin  *  diapo.zoomClick;
                }
                x_pos  +=  x_var  =  x_var  *  diapo.acceleration  +  (x_target  -  x_pos)  *  diapo.dampening;
                y_pos  +=  y_var  =  y_var  *  diapo.acceleration  +  (y_target  -  y_pos)  *  diapo.dampening;
                w_pos  +=  w_var  =  w_var  *  (diapo.acceleration  *  . 5 )  +  (w_target  -  w_pos)  *  (diapo.dampening  *  . 5 );
                h_pos  +=  h_var  =  h_var  *  (diapo.acceleration  *  . 5 )  +  (h_target  -  h_pos)  *  (diapo.dampening  *  . 5 );
                diapo.rs  +=  (Math.abs(x_var)  +  Math.abs(y_var));
                with(img.style){
                    left    =  Math.round(x_pos)  +   " px " ;
                    top     =  Math.round(y_pos)  +   " px " ;
                    width   =  Math.round(Math.max( 0 , w_pos))  +   " px " ;
                    height  =  Math.round(Math.max( 0 , h_pos))  +   " px " ;
                    zIndex  =  Math.round(w_pos);
                }
                with(spa.style){
                    left    =  Math.round(x_pos  +  w_pos  *  . 1 )  +   " px " ;
                    top     =  Math.round(y_pos  +  h_pos  *  . 1 )  +   " px " ;
                    width   =  Math.round(Math.max( 0 , w_pos  *   1.1 ))  +   " px " ;
                    height  =  Math.round(Math.max( 0 , h_pos  *   1.1 ))  +   " px " ;
                    zIndex  =  Math.round(w_pos);
                }
            }
        }
    },
    run : function(){
        diapo.xm  =  xm  -  diapo.nx;
        diapo.ym  =  ym  -  diapo.ny;
        diapo.tx_pos  +=  diapo.tx_var  =  diapo.tx_var  *  . 9   +  (diapo.tx_target  -  diapo.tx_pos)  *  . 02 ;
        diapo.txt.style.left  =  Math.round(diapo.tx_pos)  +   " px " ;
         for (var i  in  diapo.O) diapo.O[i].position();
        setTimeout( " diapo.run(); " ,  16 );
    },

images_load : function(){
        var M  =   0 ;
         for (var i = 0 ; i < diapo.N; i ++ ) {
             if (diapo.img[i].complete) {
                diapo.img[i].style.position  =   " relative " ;
                diapo.O[i].img.style.visibility  =   " visible " ;
                diapo.O[i].spa.style.visibility  =   " visible " ;
                M ++ ;
            }
            resize();
        }
         if (M < diapo.N) setTimeout( " diapo.images_load(); " ,  128 );
    },

init : function() {
        diapo.DC  =  document.getElementById( " diapoContainer " );
        diapo.img  =  diapo.DC.getElementsByTagName( " img " );
        diapo.txt  =  document.getElementById( " caption " );
        diapo.N  =  diapo.img.length;
         for (i = 0 ; i < diapo.N; i ++ ) diapo.O.push( new  diapo.CDiapo(diapo.img[i]));
        diapo.resize();
        diapo.tx_pos  =   - diapo.nw;
        diapo.tx_target  =   - diapo.nw;
        diapo.images_load();
        diapo.run();
    }
}
</ script >
</ head >
< body >
< div id = " diapoContainer " >
     < img  class = " imgsrc "  src = " http://www.webdm.cn/images/wal1.jpg " >
     < img  class = " imgsrc "  src = " http://www.webdm.cn/images/wall2.jpg " >
     < img  class = " imgsrc "  src = " http://www.webdm.cn/images/wall3.jpg " >
     < div id = " bkgcaption " ></ div >
     < div id = " caption " ></ div >
</ div >
< script type = " text/javascript " >
function dom_onload() {
     if (document.getElementById( " diapoContainer " )) diapo.init();  else  setTimeout( " dom_onload(); " ,  128 );
}
dom_onload();
</ script >
</ div >
</ body >
</ html >
< br  />
< p >< a href = " http://www.webdm.cn " > 网页代码站 </ a >   -  最专业的网页代码下载网站  -  致力为中国站长提供有质量的网页代码! </ p >
</ body >
</ html >
代码来自:http: // www.webdm.cn/webcode/e1197397-1bd2-4c9a-9c57-c3ea9c7c4b94.html

转载于:https://www.cnblogs.com/webdm/archive/2011/08/04/2127084.html

JavaScript弹性透明的图片放大代码相关推荐

  1. JavaScript 生成弹性透明的图片放大代码

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  2. JavaScript打造很酷的图片放大效果实例代码

    代码简介: 非常酷的一个JavaScript图片放大效果,不信就运行一下试试,相信你会喜欢的. 代码内容: View Code <html><head><title> ...

  3. 【淘宝】图片放大 代码

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. php鼠标移过图片放大代码,鼠标移上去,图片会自动原地放大CSS写法

    今天在制作一个zblog模板的时候,用上了这个图片放大特效,想到以前也没写过,就分享出来吧! 在我第一次接触这个特效的时候,以为会很复杂,至少会有几行代码才能去实现,但学习后真的精到了! CSS3的t ...

  5. 解决IE6透明PNG图片的代码

    使用方法 1.下载DD_belatedPNG.js文件(官方网站:http://www.dillerdesign.com/experiment/DD_belatedPNG/). 2.在网页中head区 ...

  6. vue项目 一行js代码搞定点击图片放大缩小

    一行js代码搞定xue项目需要点击图片放大缩小,其实主要用的是用到了vue:class的动态切换,内容比较简单.一开始我把维护的需求想得太复杂了,和测试小姐姐聊了一下才反应过来. 两个月不到跟了四个项 ...

  7. 使用JavaScript 中的Math对象和勾股定理公式,计算鼠标的位置与页面图片中心点的距离,根据距离对页面上的图片进行放大或缩小处理。距离远时图片放大,距离近时图片缩小

    查看本章节 查看作业目录 需求说明: 使用JavaScript 中的Math对象和勾股定理公式,计算鼠标的位置与页面图片中心点的距离,根据距离对页面上的图片进行放大或缩小处理.距离远时图片放大,距离近 ...

  8. jQuery插件Magnify放大镜实现javascript图片放大功能

    jQuery插件Magnify放大镜实现javascript图片放大功能 博客所有文章均属原创作品,如有转载,请注明作者:biuuu,来源:http://www.biuuu.com/?p=459 有时 ...

  9. js实现放大镜效果(图片放大)—JavaScript

    今天来做一个非常常见且有意思的的案例,就是我们的鼠标经过图片放大的一个效果! 具体实现的效果看下面这张图  案例分析: 黄色的遮挡层跟随鼠标功能. 把鼠标坐标给遮挡层不合适.因为遮挡层坐标以父盒子为准 ...

最新文章

  1. 机器人导航两篇顶级会议论文解析
  2. Python 使用控制台运行带有相对路径的指令时,是以运行文件为基准,还是以控制台当前路径为基准
  3. linux -组管理和权限管理
  4. 初探Stage3D(一) 3D渲染基础原理
  5. fastreport 直接调网络打印机_为什么UV打印机不能打印凹凸不平的材料?
  6. css英文左右对齐,中文英文左右padding一致两端对齐实现_js
  7. 远程办公、游戏迅猛增长,旅行、汽车业遭重创!疫期移动互联网行业报告解读...
  8. [Android Pro] 内容提供者ContentProvider的基本使用
  9. mysql用 fifo 记录日志_Python学习第四十七天记录打call:mysqlclient操作MySQL关系型数据库...
  10. 音乐直链php,【原创】百度音乐直链 + 实现方法
  11. Halcon找圆系列(1)如何检测圆形
  12. iOS面试前的准备计划(2022)
  13. 数据的准确性对模型效果的重要性
  14. GitHub上Java捕鱼达人源码分析(fishlord)
  15. 安装依赖报错:An unexpected error occurred: “E:\\ReactProject\\umi-project\\package.json:
  16. 国际性PRO-SID研究开始招募患者,该研究评估Panzyga(R)用于慢性淋巴细胞白血病和继发性免疫缺陷患者的一级预防性治疗
  17. shell向文件末尾添加内容
  18. 光线投射与光线跟踪算法归纳
  19. 软件实习项目2——贪吃喵(猫吃鱼版贪吃蛇)(成品展示)
  20. Android aosp源码阅读

热门文章

  1. Intel Technology Journal
  2. Android LiveData初识
  3. Android攻城狮fragment
  4. JS纯前端实现卡通人物图片的动态效果
  5. 没学历可以学IT吗?
  6. 智能ALMP封装推拉力测试机 剪切力强度测试仪器主要功能介绍
  7. ABAP LVC DEMO程序
  8. latex大括号 多行公式_如何快速入门 LaTeX,在 XMind 2020 中轻松输入方程。
  9. 微信小程序基础学习(2)- 模板与配置:WXML 模板语法、WXSS 模板样式、全局配置、页面配置、网络数据请求
  10. Android Framework 记录之一