JavaScript图片特效代码
来源:广州中睿信息技术有限公司官网
发布时间:2012/10/21 23:25:16 编辑:editor 阅读 301
代码简介:一个老外完成的JS图片特效,运用了特殊算法,将多幅图片组合在一起,使浏览器变得智能起来,当移上某个图片的时候,图片会慢慢放大一些并靠近你,如果点击的话,会快速放大到你的眼前,其它的远去或变

代码简介:

一个老外完成的JS图片特效,运用了特殊算法,将多幅图片组合在一起,使浏览器变得智能起来,当移上某个图片的时候,图片会慢慢放大一些并靠近你,如果点击的话,会快速放大到你的眼前,其它的远去或变暗。可能算法原因,运行后CPU占用很历害,电脑有点慢。 function showTip() { var obj = document.getElementById('coder-yqts'); if (obj.style.display == "none") { obj.style.display = "block"; } else { obj.style.display = "none"; } }

代码内容:

View Code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>【荐】一个漂亮的JavaScript图片特效代码_网页代码站(www.webdm.cn)</title>
<style type=
"text/css">
    html {
        
overflow: hidden;
    }
    body {
        
position: absolute;
        margin: 0px;
        padding: 0px;
        background: #111;
        width: 100%;
        height: 100%;
    }
    #screen {
        
position: absolute;
        left: 10%;
        top: 10%;
        width: 80%;
        height: 80%;
        background: #000;
    }
    #screen img {
        
position: absolute;
        cursor: pointer;
        visibility: hidden;
        width: 0px;
        height: 0px;
    }
    #screen .tvover {
        
border: solid #876;
        opacity: 1;
        filter: alpha(opacity=100);
    }
    #screen .tvout {
        
border: solid #fff;
        opacity: 0.7;
    }
    #bankImages {
        
display: none;
    }
</style>

<script type=
"text/javascript">
var Library = {}
;
Library.ease = function () {
    this.target = 
0;
    this.position = 0;
    this.move = function (target, speed)
    {
        this.position += (target - this.position) * speed
;
    }
}

var tv = {
    O : [],
    screen : {},
    grid : {
        size       : 
4,
        borderSize : 
6,
        zoomed     : false
    },
    angle : {
        x : new Library.ease(),
        y : new Library.ease()
    },
    camera : {
        x    : new Library.ease(),
        y    : new Library.ease(),
        zoom : new Library.ease(),
        focalLength : 
750 // http://www.codefans.net
    },

    init : function ()
    {
        this.screen.obj = document.getElementById(
'screen');
        var img = document.getElementById('bankImages').getElementsByTagName('img');
        this.screen.obj.onselectstart = function () { return false; }
        this.screen.obj.ondrag = function () { return false; }
        var ni = 0;
        var n = (tv.grid.size / 2) - .5;
        for (var y = -n; y <= n; y++)
        {
            for (var x = -n
; x <= n; x++)
            {
                var o = document.createElement(
'img');
                var i = img[(ni++) % img.length];
                o.className = 'tvout';
                o.src = i.src;
                tv.screen.obj.appendChild(o);
                o.point3D = {
                    x  : x,
                    y  : y,
                    z  : new Library.ease()
                }
;
                o.point2D = {};
                o.ratioImage = 1;
                tv.O.push(o);
                o.onmouseover = function ()
                {
                    if (!tv.grid.zoomed)
                    {
                        if (tv.o)
                        {
                            tv.o.point3D.z.target = 
0;
                            tv.o.className = 'tvout';
                        }
                        this.className = 
'tvover';
                        this.point3D.z.target = -.5;
                        tv.o = this;
                    }
                }
                o.onclick = function ()
                {
                    if (!tv.grid.zoomed)
                    {
                        tv.camera.x.target = this.point3D.x
;
                        tv.camera.y.target = this.point3D.y;
                        tv.camera.zoom.target = tv.screen.w * 1.25;
                        tv.grid.zoomed = this;
                    } else {
                        if (this == tv.grid.zoomed){
                            tv.camera.x.target = 
0;
                            tv.camera.y.target = 0;
                            tv.camera.zoom.target = tv.screen.w / (tv.grid.size + .1);
                            tv.grid.zoomed = false;
                        }
                    }
                }
                o.calc = function ()
                {
                    this.point3D.z.move(this.point3D.z.target, .
5);
                    var x = (this.point3D.x - tv.camera.x.position) * tv.camera.zoom.position;
                    var y = (this.point3D.y - tv.camera.y.position) * tv.camera.zoom.position;
                    var z = this.point3D.z.position * tv.camera.zoom.position;
                    var xy = tv.angle.cx * y  - tv.angle.sx * z;
                    var xz = tv.angle.sx * y  + tv.angle.cx * z;
                    var yz = tv.angle.cy * xz - tv.angle.sy * x;
                    var yx = tv.angle.sy * xz + tv.angle.cy * x;
                    this.point2D.scale = tv.camera.focalLength / (tv.camera.focalLength + yz);
                    this.point2D.x = yx * this.point2D.scale;
                    this.point2D.y = xy * this.point2D.scale;
                    this.point2D.w = Math.round(
                                       Math.max(
                                         
0,
                                         this.point2D.scale * tv.camera.zoom.position * .
8
                                       )
                                     )
;
                    if (this.ratioImage > 1)
                        this.point2D.h = Math.round(this.point2D.w / this.ratioImage)
;
                    else
                    {
                        this.point2D.h = this.point2D.w
;
                        this.point2D.w = Math.round(this.point2D.h * this.ratioImage);
                    }
                }
                o.draw = function ()
                {
                    if (this.complete)
                    {
                        if (!this.loaded)
                        {
                            if (!this.img)
                            {
                                this.img = new Image()
;
                                this.img.src = this.src;
                            }
             &n
联系我们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