图片破碎 效果

 

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

 效果图:

代码:

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

 

转载于:https://www.cnblogs.com/web-fusheng/p/6836296.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值