图片破碎 效果

图片先显示 而后化为颗粒 、飞出、消失

效果图:

代码:

<!DOCTYPE>
<html>
<head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <title></title>
    <style type="text/css">
        .boomCont{
            width: 400px;
            height: 220px;
            position: absolute;
            top: 0px;right: 0px;
            bottom: 0px;left: 0px;
            margin: auto;
            /*overflow: hidden;*/
            /*border: 1px solid red;*/
            /*display: flex;*/
        }
        .test-img{
            width: 400px;
            position: absolute;
            /*display: none;*/
            z-index: 10;
        }
        .item-ball{
            position: relative;
            top: 0px;left: 0px;
            float: left;
            background: url("test-img/t1.jpg");
            transition:all 1.8s linear;
            /*background-size:500px 400px;*/
            /*background-color: black;*/
            border-radius: 50%;
        }
        .item-ball:nth-child(1){
            display: none;
        }
    </style>
</head>
<body>
        <div class="boomCont" id="boomCont">
            <div class="item-ball"></div>
            <img class="test-img" src="test-img/t1.jpg" alt="">
        </div>

</body>
<script src="js/jquery-1.11.3.js"></script>
<script type="text/JavaScript">
    var box=document.getElementById(‘boomCont‘),
         ball=document.getElementsByClassName(‘item-ball‘)[0],
         frag=document.createDocumentFragment(),
         dia=10,   //直径
         //中心点坐标
         xC= box.getBoundingClientRect().left+box.getBoundingClientRect().width/ 2,
         yC= box.getBoundingClientRect().top+box.getBoundingClientRect().height/ 2,
         rNum=parseInt(box.getBoundingClientRect().height/dia),
         cNum=parseInt(box.getBoundingClientRect().width/dia) ;
    ball.style.width=dia+‘px‘;ball.style.height=dia+‘px‘;
    for(var r=0;r<rNum;r++){
        for (var c=0;c<cNum;c++){
            var cl=ball.cloneNode(true);
            ball.style.backgroundPosition=‘-‘+c*dia+‘px ‘+‘-‘+r*dia+‘px‘;
            frag.appendChild(cl);
        }
    }
    box.appendChild(frag);
    function randNum(min,max){
        return (Math.random()*(max - min)+min);
    }
    function disappear(){
        console.log(xC,yC);
        $(‘.test-img‘).fadeOut(1000);
      $(‘.item-ball‘).each(function(){
          $(this).animate({
              ‘top‘:randNum(-110,110)+‘px‘,
              ‘left‘:randNum(-200,200)+‘px‘,
              ‘transform‘:‘scale(‘+randNum(0.3,1.8)+‘)‘,
              ‘opacity‘:0
          });
      });
    }
    disappear();

</script>
</html>
时间: 2024-08-28 06:23:14

图片破碎 效果的相关文章

图片破碎 效果 修正

以前做的 图片破碎的程序,后来发现有点问题: 即多出一部分,现在给图像背景设置个偏移量,完美解决: 完整代码: <!DOCTYPE> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title></title> <style type="text/css&qu

超厉害的CSS3图片破碎爆炸效果!

Java代码   var fx  = { buffer : function(obj, cur, target, fnDo, fnEnd, fs){ if(!fs)fs=6; var now={}; var x=0; var v=0; if(!obj.__last_timer)obj.__last_timer=0; var t=new Date().getTime(); if(t-obj.__last_timer>20) { fnMove(); obj.__last_timer=t; } cle

Unity 实现物体破碎效果(转)

感谢网友分享,原文地址(How to Make an Object Shatter Into Smaller Fragments in Unity),中文翻译地址(Unity实现物体破碎效果) In this tutorial I will show you how to create a simple shattering effect for your Unity game. Instead of just "deleting" a crate (or any other obje

JS实现有点炫的图片展示效果-图片解体和组合

经过4个月的努力学习,迎来了进入市场的最后一个学习项目.自己模仿了一个图片展示效果,用在了项目中,感觉挺炫的.在这里分享一下,希望大家喜欢~! bomb-showImg : 在线演示http://runjs.cn/detail/tl9quyke查看源码http://runjs.cn/code/tl9quyke HTML : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

原生 JavaScript 图片裁剪效果

图片裁剪程序效果如下,可鼠标操作. 拖动左边小方框时在右侧实时显示对应的裁剪图片,同时左侧的拖动框里图片完全显示,拖动框外部图片模糊显示.8个控制点可以对显示区域大小进行控制. HTML 和 CSS 部分 左侧的裁剪操作区域可以分为三层. 最底层的图片半透明效果:中间层的图片只显示制定区域,其他部分隐藏:最上层为拖拽控制层.最低层和中间层使用同一张图片,利用CSS属性clip控制中间层只显示一部分. 三个层都使用 absolute 绝对定位.下面是 HTML 和 CSS 代码. 1 <div i

网站——循环图片切换效果(最近做网站,已经快炸了)

看一下效果 <!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" lang="zh-cn"><head><meta

一款在论坛上看到的JS封装的随机过渡方式的图片切换效果

<!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-

CSS3 实现六边形Div图片展示效果

效果图: 实现原理: 这个效果的主要css样式有: 1.>transform: rotate(120deg); 图片旋转 2.>overflow:hidden;  超出隐藏 3.>visibility: hidden;  也是隐藏,与display:none;相似,但不同的是,它虽然隐藏了,但依然会在网页中占有位置 我们要用到3层div进行旋转来得到这个效果(ps:3层div的大小是一样的). 最外层div(boxF)旋转120度.第二层(boxS)旋转-60度,第三层(boxT)再旋转

图片剪切效果

第一篇博文,把今天写的一个实现图片剪切效果的JS脚本发上来 基本思路: 三层结构,第一层为透明度是0.7的图片,第二层为正常的图片,第三层使用一个DIV作为选取框,采用CSS中的绝对定位进行覆盖 HTML代码 <div id="box"> <img id="img-1" src="imgs/cat-1.jpg"/> <img id="img-2" src="imgs/cat-2.jpg&