一款超炫的图片排列特效

今天给大家分享一款超炫的图片排列特效。页面加载时。图片纵向堆叠在页面中,当鼠标单击toggle按钮时,图片依次展开。铺满整个网页。效果图如下:

在线预览   源码下载

实现的代码。

html代码:

 <div class="t-container">
        <div class="t-content">
            <img class="t-img" src="img00.jpg"
                alt="" />
            <div class="cover">
            </div>
        </div>
        <div class="t-content">
            <img class="t-img" src="img01.jpg"
                alt="" />
            <div class="cover">
            </div>
        </div>
        <div class="t-content">
            <img class="t-img" src="img02.jpg"
                alt="" />
            <div class="cover">
            </div>
        </div>
        <div class="t-content">
            <img class="t-img" src="img03.jpg"
                alt="" />
            <div class="cover">
            </div>
        </div>
        <div class="t-content">
            <img class="t-img" src="img04.jpg"
                alt="" />
            <div class="cover">
            </div>
        </div>
        <div class="t-content">
            <img class="t-img" src="img05.jpg"
                alt="" />
            <div class="cover">
            </div>
        </div>
        <div class="t-content">
            <img class="t-img" src="img06.jpg"
                alt="" />
            <div class="cover">
            </div>
        </div>
        <div class="t-content">
            <img class="t-img" src="img07.jpg"
                alt="" />
            <div class="cover">
            </div>
        </div>
        <div class="t-content">
            <img class="t-img" src="img08.jpg"
                alt="" />
            <div class="cover">
            </div>
        </div>
        <div class="t-content">
            <img class="t-img" src="img09.jpg"
                alt="" />
            <div class="cover">
            </div>
        </div>
        <div class="t-content">
            <img class="t-img" src="img10.jpg"
                alt="" />
            <div class="cover">
            </div>
        </div>
        <div class="t-content">
            <img class="t-img" src="img11.jpg"
                alt="" />
            <div class="cover">
            </div>
        </div>
    </div>
    <div class="container">
        <button type="button" class="btn btn-primary" id="toggle">
            Toggle</button>
    </div>

css3代码:

   body
        {
            overflow: hidden;
        }

        canvas
        {
            width: 100%;
            height: 100%;
        }

        .t-container
        {
            position: absolute;
            top: 0;
            left: 0;
        }
        .t-container .t-content
        {
            position: absolute;
            top: 0;
            left: 0;
            width: 400px;
            height: 225px;
        }
        .t-container .t-content img
        {
            position: absolute;
            width: 400px;
            height: 225px;
        }
        .t-container .t-content .cover
        {
            position: absolute;
            top: 0;
            left: 0;
            background-color: rgba(0, 0, 0, 0.75);
            width: 400px;
            height: 225px;
        }

        .container
        {
            position: absolute;
            -moz-transform: translateX(-50%);
            -ms-transform: translateX(-50%);
            -webkit-transform: translateX(-50%);
            transform: translateX(-50%);
            left: 50%;
            bottom: 50px;
        }
        .container .btn
        {
            z-index: 9999;
        }

js代码:

  function createGrid(transform, xx, yy, isHorizon) {
            var elemWidth, elemHeight;

            if (isHorizon) {
                elemWidth = window.innerWidth / 4;
                elemHeight = window.innerHeight / 3;
            } else {
                elemWidth = window.innerWidth / 3;
                elemHeight = window.innerHeight / 4;
            }

            var xPos = elemWidth * xx;
            var yPos = elemHeight * yy;

            var curTopLeft = { x: transform.topLeft.x, y: transform.topLeft.y };
            var curTopRight = { x: transform.topRight.x, y: transform.topRight.y };
            var curBotLeft = { x: transform.bottomLeft.x, y: transform.bottomLeft.y };
            var curBotRight = { x: transform.bottomRight.x, y: transform.bottomRight.y };

            var targetTopLeft = { x: xPos, y: yPos };
            var targetTopRight = { x: xPos + elemWidth, y: yPos };
            var targetBotLeft = { x: xPos, y: yPos + elemHeight };
            var targetBotRight = { x: xPos + elemWidth, y: yPos + elemHeight };

            var curObject = { rate0: 1, rate1: 1, rate2: 1, rate3: 1, rate4: 1 };

            function onUpdateGridHandler() {
                var tempTopLeftX = curTopLeft.x * curObject.rate + targetTopLeft.x * (1 - curObject.rate);
                var tempTopLeftY = curTopLeft.y * curObject.rate + targetTopLeft.y * (1 - curObject.rate);

                var tempTopRightX = curTopRight.x * curObject.rate + targetTopRight.x * (1 - curObject.rate);
                var tempTopRightY = curTopRight.y * curObject.rate + targetTopRight.y * (1 - curObject.rate);

                var tempBotLeftX = curBotLeft.x * curObject.rate + targetBotLeft.x * (1 - curObject.rate);
                var tempBotLeftY = curBotLeft.y * curObject.rate + targetBotLeft.y * (1 - curObject.rate);

                var tempBotRightX = curBotRight.x * curObject.rate + targetBotRight.x * (1 - curObject.rate);
                var tempBotRightY = curBotRight.y * curObject.rate + targetBotRight.y * (1 - curObject.rate);

                transform.topLeft.x = tempTopLeftX;
                transform.topLeft.y = tempTopLeftY;

                transform.topRight.x = tempTopRightX;
                transform.topRight.y = tempTopRightY;

                transform.bottomLeft.x = tempBotLeftX;
                transform.bottomLeft.y = tempBotLeftY;

                transform.bottomRight.x = tempBotRightX;
                transform.bottomRight.y = tempBotRightY;

            }

            function onUpdate0GridHandler() {

                var tempTopLeftX = curTopLeft.x * curObject.rate0 + targetTopLeft.x * (1 - curObject.rate0);
                var tempTopLeftY = curTopLeft.y * curObject.rate0 + targetTopLeft.y * (1 - curObject.rate0);

                transform.topLeft.x = tempTopLeftX;
                transform.topLeft.y = tempTopLeftY;
            }

            function onUpdate1GridHandler() {

                var tempTopRightX = curTopRight.x * curObject.rate1 + targetTopRight.x * (1 - curObject.rate1);
                var tempTopRightY = curTopRight.y * curObject.rate1 + targetTopRight.y * (1 - curObject.rate1);

                transform.topRight.x = tempTopRightX;
                transform.topRight.y = tempTopRightY;

            }

            function onUpdate2GridHandler() {

                var tempBotLeftX = curBotLeft.x * curObject.rate2 + targetBotLeft.x * (1 - curObject.rate2);
                var tempBotLeftY = curBotLeft.y * curObject.rate2 + targetBotLeft.y * (1 - curObject.rate2);

                transform.bottomLeft.x = tempBotLeftX;
                transform.bottomLeft.y = tempBotLeftY;

            }

            function onUpdate3GridHandler() {

                var tempBotRightX = curBotRight.x * curObject.rate3 + targetBotRight.x * (1 - curObject.rate3);
                var tempBotRightY = curBotRight.y * curObject.rate3 + targetBotRight.y * (1 - curObject.rate3);

                transform.bottomRight.x = tempBotRightX;
                transform.bottomRight.y = tempBotRightY;

            }

            TweenLite.to(curObject, .4, { rate0: 0, onUpdate: onUpdate0GridHandler, ease: "Power2.easeOut" });
            TweenLite.to(curObject, .4, { rate1: 0, onUpdate: onUpdate1GridHandler, ease: "Power1.easeOut" });
            TweenLite.to(curObject, .4, { rate2: 0, onUpdate: onUpdate2GridHandler, ease: "Power4.easeOut" });
            TweenLite.to(curObject, .4, { rate3: 0, onUpdate: onUpdate3GridHandler, ease: "Power3.easeOut" });

            //console.log(transform)
            var cover = $(transform.element).find(".cover")[0]
            TweenLite.to(cover, .4, { opacity: 0, ease: "Power1.easeOut" });
        }
        function pileElement(transform, num, maxNumber) {
            var windowWidth = window.innerWidth;
            var windowHeight = window.innerHeight;

            // -----------------------------

            var camera = {
                focus: 400,
                self: {
                    x: 0,
                    y: 0,
                    z: 0
                },
                rotate: {
                    x: 0,
                    y: 0,
                    z: 0
                },
                up: {
                    x: 0,
                    y: 1,
                    z: 0
                },
                zoom: 1,
                display: {
                    x: width / 2,
                    y: height / 2,
                    z: 0
                }
            };

            // ================================

            var y = -10 * (num + 1) + window.innerHeight / 2 * .8;
            var width = 400;
            var height = 400 * 9 / 16;
            var topLeftPos = { x: -width / 2, z: -height };
            var topRightPos = { x: width / 2, z: -height };
            var botLeftPos = { x: -width / 2, z: 0 };
            var botRightPos = { x: width / 2, z: 0 };

            var topScale = ((camera.focus - camera.self.z) / ((camera.focus - camera.self.z) - topLeftPos.z)) * camera.zoom;
            var botScale = ((camera.focus - camera.self.z) / ((camera.focus - camera.self.z) - botLeftPos.z)) * camera.zoom; //console.log("topScale: " + topScale); //console.log("BotScale: " + botScale);

            var targetTopLeftX = topScale * topLeftPos.x;
            var targetTopLeftY = topScale * y;

            var targetTopRightX = topScale * topRightPos.x;
            var targetTopRightY = topScale * y;

            var targetBotLeftX = botScale * botLeftPos.x;
            var targetBotLeftY = botScale * y;

            var targetBotRightX = botScale * botRightPos.x;
            var targetBotRightY = botScale * y;

            var halfWidth = window.innerWidth / 2;
            var halfHeight = window.innerHeight / 2;

            // --------------------------------------

            transform.topLeft.x = targetTopLeftX + halfWidth;
            transform.topLeft.y = targetTopLeftY + halfHeight;

            transform.topRight.x = targetTopRightX + halfWidth;
            transform.topRight.y = targetTopRightY + halfHeight;

            transform.bottomLeft.x = targetBotLeftX + halfWidth;
            transform.bottomLeft.y = targetBotLeftY + halfHeight;

            transform.bottomRight.x = targetBotRightX + halfWidth;
            transform.bottomRight.y = targetBotRightY + halfHeight;

        };

        function createPile(transform, num) {
            var windowWidth = window.innerWidth;
            var windowHeight = window.innerHeight;

            // -----------------------------

            var camera = {
                focus: 400,
                self: {
                    x: 0,
                    y: 0,
                    z: 0
                },
                rotate: {
                    x: 0,
                    y: 0,
                    z: 0
                },
                up: {
                    x: 0,
                    y: 1,
                    z: 0
                },
                zoom: 1,
                display: {
                    x: width / 2,
                    y: height / 2,
                    z: 0
                }
            };

            // ================================
            var halfWidth = window.innerWidth / 2;
            var halfHeight = window.innerHeight / 2;

            var y = -10 * (num + 1) + window.innerHeight / 2 * .8;
            var width = 400;
            var height = 400 * 9 / 16;
            var topLeftPos = { x: -width / 2, z: -height };
            var topRightPos = { x: width / 2, z: -height };
            var botLeftPos = { x: -width / 2, z: 0 };
            var botRightPos = { x: width / 2, z: 0 };

            var topScale = ((camera.focus - camera.self.z) / ((camera.focus - camera.self.z) - topLeftPos.z)) * camera.zoom;
            var botScale = ((camera.focus - camera.self.z) / ((camera.focus - camera.self.z) - botLeftPos.z)) * camera.zoom; //console.log("topScale: " + topScale); //console.log("BotScale: " + botScale);

            var targetTopLeftX = topScale * topLeftPos.x + halfWidth;
            var targetTopLeftY = topScale * y + halfHeight;

            var targetTopRightX = topScale * topRightPos.x + halfWidth;
            var targetTopRightY = topScale * y + halfHeight;

            var targetBotLeftX = botScale * botLeftPos.x + halfWidth;
            var targetBotLeftY = botScale * y + halfHeight;

            var targetBotRightX = botScale * botRightPos.x + halfWidth;
            var targetBotRightY = botScale * y + halfHeight;

            var curTopLeft = { x: transform.topLeft.x, y: transform.topLeft.y };
            var curTopRight = { x: transform.topRight.x, y: transform.topRight.y };
            var curBotLeft = { x: transform.bottomLeft.x, y: transform.bottomLeft.y };
            var curBotRight = { x: transform.bottomRight.x, y: transform.bottomRight.y };

            var targetTopLeft = { x: targetTopLeftX, y: targetTopLeftY };
            var targetTopRight = { x: targetTopRightX, y: targetTopRightY };
            var targetBotLeft = { x: targetBotLeftX, y: targetBotLeftY };
            var targetBotRight = { x: targetBotRightX, y: targetBotRightY };

            var curObject = { rate0: 1, rate1: 1, rate2: 1, rate3: 1, rate4: 1 };

            function onUpdate0GridHandler() {

                var tempTopLeftX = curTopLeft.x * curObject.rate0 + targetTopLeft.x * (1 - curObject.rate0);
                var tempTopLeftY = curTopLeft.y * curObject.rate0 + targetTopLeft.y * (1 - curObject.rate0);

                transform.topLeft.x = tempTopLeftX;
                transform.topLeft.y = tempTopLeftY;
            }

            function onUpdate1GridHandler() {

                var tempTopRightX = curTopRight.x * curObject.rate1 + targetTopRight.x * (1 - curObject.rate1);
                var tempTopRightY = curTopRight.y * curObject.rate1 + targetTopRight.y * (1 - curObject.rate1);

                transform.topRight.x = tempTopRightX;
                transform.topRight.y = tempTopRightY;

            }

            function onUpdate2GridHandler() {

                var tempBotLeftX = curBotLeft.x * curObject.rate2 + targetBotLeft.x * (1 - curObject.rate2);
                var tempBotLeftY = curBotLeft.y * curObject.rate2 + targetBotLeft.y * (1 - curObject.rate2);

                transform.bottomLeft.x = tempBotLeftX;
                transform.bottomLeft.y = tempBotLeftY;

            }

            function onUpdate3GridHandler() {

                var tempBotRightX = curBotRight.x * curObject.rate3 + targetBotRight.x * (1 - curObject.rate3);
                var tempBotRightY = curBotRight.y * curObject.rate3 + targetBotRight.y * (1 - curObject.rate3);

                transform.bottomRight.x = tempBotRightX;
                transform.bottomRight.y = tempBotRightY;

            }

            TweenLite.to(curObject, .4, { rate0: 0, onUpdate: onUpdate0GridHandler, ease: "Power1.easeOut" });
            TweenLite.to(curObject, .4, { rate1: 0, onUpdate: onUpdate1GridHandler, ease: "Power1.easeOut" });
            TweenLite.to(curObject, .4, { rate2: 0, onUpdate: onUpdate2GridHandler, ease: "Power3.easeOut" });
            TweenLite.to(curObject, .4, { rate3: 0, onUpdate: onUpdate3GridHandler, ease: "Power3.easeOut" });

            var cover = $(transform.element).find(".cover")[0];
            TweenLite.to(cover, .4, { opacity: 1, ease: "Power1.easeIn" });

            // --------------------------------------

            /*
            transform.topLeft.x = targetTopLeftX + halfWidth;
            transform.topLeft.y = targetTopLeftY + halfHeight;

            transform.topRight.x = targetTopRightX + halfWidth;
            transform.topRight.y = targetTopRightY + halfHeight;

            transform.bottomLeft.x = targetBotLeftX + halfWidth;
            transform.bottomLeft.y = targetBotLeftY + halfHeight;

            transform.bottomRight.x = targetBotRightX + halfWidth;
            transform.bottomRight.y = targetBotRightY + halfHeight;*/

        };

        (function () {
            // create PerspectiveTransfrom
            var elem = document.getElementById("t-content00");
            var width = 400;
            var height = 225;
            var useBackFacing = true;
            var curCount;
            var $elem = $(".t-content");
            var isHorizon = false;
            var isAnimation = true;
            var isOpen = true;
            if (window.innerWidth > window.innerHeight) isHorizon = true;

            var transformArr = [];

            //console.log(typeof $elem);
            $elem.each(function (index) {
                var transform = new PerspectiveTransform(this, width, height, true);
                transformArr.push(transform);
            });

            curCount = transformArr.length - 1;

            //

            $elem.each(function (index) {
                var transform = transformArr[index]
                pileElement(transform, index);
            });

            function animation() {
                isAnimation = true;
                var transformCount = transformArr.length - curCount - 1;
                var xx, yy;

                if (isHorizon) {
                    xx = transformCount % 4;
                    yy = parseInt(transformCount / 4);
                } else {
                    xx = transformCount % 3;
                    yy = parseInt(transformCount / 3);
                }

                createGrid(transformArr[curCount], xx, yy, isHorizon);

                curCount--;
                if (curCount >= 0) {

                    setTimeout(animation, 100);
                }
                else isAnimation = false;
            }

            function animation2() {
                isAnimation = true;

                createPile(transformArr[curCount], curCount)

                curCount++;
                if (curCount <= transformArr.length - 1) setTimeout(animation2, 50);
                else isAnimation = false;
            };

            function loop() {

                $elem.each(function (index) {
                    transformArr[index].update();
                });

                requestAnimationFrame(loop);
            };

            loop();

            setTimeout(animation, 500);

            $("#toggle").click(function (ev) {
                if (!isAnimation) {

                    if (isOpen) {
                        curCount = 0;
                        animation2();
                    }
                    else {
                        curCount = transformArr.length - 1;
                        animation();
                    }

                    isOpen = !isOpen;
                }
            });
        })();

注:本文爱编程原创文章,转载请注明原文地址:http://www.w2bc.com/Article/11827

时间: 2024-12-20 01:10:26

一款超炫的图片排列特效的相关文章

一款基于jquery超炫的图片切换特效

今天为给大家介绍一款基于jquery超炫的图片切换特效.由百叶窗飞入显示图片.图片消息的时候也是百叶窗渐行渐远.用于图片展示,效果还是非常好,我们一起看下效果图: 在线预览   源码下载 来看下实现的代码.注意了,这里有引用jquery和underscore插件. html代码: <div class="wrap"> <div class="box active" style="background-image: url(img/1.jp

iHover &ndash; 30+ 纯 CSS3 实现的超炫的图片悬停特效

iHover 是一个令人印象深刻的图片悬停效果集合,完全基于 CSS3 实现,无依赖,能够搭配 Bootstrap 3 很好地工作.基于 SCSS 技术构建(包括文件),便于修改变量.有模块化的代码,无需包含整个文件. 把饭 30 多个悬停效果,满足各种需要. https://github.com/gudh/ihover https://github.com/gudh/ihover iHover – 30+ 纯 CSS3 实现的超炫的图片悬停特效

一款纯css3实现的超炫动画背画特效

之前为大家介绍了很多款由纯css3实现的特效.今天要再给大家带来一款纯css3实现的超炫动画背画特效.代码非常简单,没有引用任何其它js代码.css代码也不多.效果非常炫.一起看下效果图: 在线预览   源码下载 实现的代码. html代码: <div class='fake-gif'> <span class='stripe'></span><span class='stripe'></span><span class='stripe'&

你见过吗?9款超炫的复选框(Checkbox)效果

复选框(Checkbox)在各个浏览器中的效果不一致,因此很多 Web 开发人员会自己重新设计一套界面和使用体验都更佳的复选框功能.下面就给大家分享9款超炫的复选框(Checkbox)效果,纯 CSS3 实现,未使用任何图片. 温馨提示:为保证最佳的效果,请在 IE10+.Chrome.Firefox 和 Safari 等现代浏览器中浏览. 前面三款效果都是灵感来自移动应用程序的滑动选择框效果,在选择和未选择状态之间通过滑动来切换效果,非常的动感.效果的实现方面是借用了一个 DIV 标签和一个

jquery 实现的一款超简单的图片切换功能

<html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" src="./assets/js/jquery.js"></script></head><style> </st

Cool!15个超炫的 CSS3 文本特效【上篇】

每一个网页设计师都希望创建出让用户能够赏识的网站.当然,这是不可能满足每个人的口味的.幸运的是,我们有最强大的工具和资源.实际上,我们非常多的网站模板,框架,内容管理系统,先进的工具和其他的资源可以使用. 这篇文章展示了使用一组使用 CSS3 制作的文本特效,快来欣赏. 您可能感兴趣的相关文章 小伙伴们惊呆了!8个超炫的 Web 效果 8个惊艳的 HTML5 和 JavaScript 特效 10大 Metro UI 风格 Bootstrap 主题 35款精致的 CSS3 和 HTML5 网页模板

10款超炫的开源jquery的源码预览效果

1.Flat Surface Shader – 超炫的 3D 模拟照明效果 Flat Surface Shader 是一个超炫的 3D 模拟照明效果,可以配置使用基于 Canvas 的 2D 上下文或者基于 SVG 多边形数组绘制三角形.它还采用原生的 Float32Arrays 存储数字数据,进行高度优化的计算.可以调整颜色参数预览效果,而且可以导出图像. 在线演示 源码下载 2.Sidr – 创建侧栏和响应式菜单的最佳 jQuery 插件 侧栏隐藏菜单是一个很好的方式,使得用户可以在需要的时

css3超炫8种loading加载特效

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Typ

7款超酷HTML5 3D动画精选应用及源码

对以前来讲,3D动画拿到网页上展示是一件非常奢侈的事情,第一是浏览器不够先进,第二是大部分只能用flash实现伪3D.HTML5的出现,让实现网页3D动画变得非常简单,当然前提是你不要再使用像IE678之类的浏览器了.下面精选的几款HTML5 3D动画,希望你会喜欢. 1.HTML5 SVG 3D空间模型 可拖拽缩放 这是一个基于HTML5和SVG的3D空间模型,这个3D模型提供了x.y.z三个坐标轴以及一个平面网格.我们可以对这个HTML5 3D模型进行缩放.拖拽.翻转等操作,这些操作可以通过