图片放大代码
来源:广州中睿信息技术有限公司官网
发布时间:2012/10/21 23:25:16 编辑:editor 阅读 484
代码简介:JavaScript算法生成弹性透明的图片放大效果,代码值得看一下哦,弹性和缓冲是一个意思,JS缓冲效果在网页中使用很频繁,使用缓冲技术可以制作出超多的精美特效来。代码内容:ViewCod

代码简介:

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 * 100else 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)<100for(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;
             &
联系我们CONTACT 扫一扫
愿景:成为最专业的软件研发服务领航者
中睿信息技术有限公司 广州•深圳 Tel:020-38931912 务实 Pragmatic
广州:广州市天河区翰景路1号金星大厦18层中睿信息 Fax:020-38931912 专业 Professional
深圳:深圳市福田区车公庙有色金属大厦509~510 Tel:0755-25855012 诚信 Integrity
所有权声明:PMI, PMP, Project Management Professional, PMI-ACP, PMI-PBA和PMBOK是项目管理协会(Project Management Institute, Inc.)的注册标志。
版权所有:广州中睿信息技术有限公司 粤ICP备13082838号-2