自己写的触壁反弹效果!!js

贴码

<script>
                    //容器寬高
                   var banner_x=$('.index-two').width()-320;
                   var banner_y=$('.index-two').height()-280;
                   var time;
                    var type_l;
                   //計時器
                   function reload(){
                        var left=parseInt($('.index-two-title').find('img').css('left').replace("px",""));
                        var top=parseInt($('.index-two-title').find('img').css('top').replace("px",""));
                       var type;
                       function check_type(){
                           type=Math.round(Math.random()*2 + 2);
                            if(type==type_l){
                              check_type();  
                            }
                       }
                       check_type();
                       if(type==1){
                         var x= 0;
                         var y=0;
                       }else if(type==2){
                         var x=0;
//                         var y=banner_y;
                         var y=Math.round(Math.random()*banner_y);
                       }else if(type==3){
                         var x=Math.round(Math.random()*banner_x);
                         var y=0;
                       }else{
                         var x=banner_x;
                         var y=banner_y;
                       }
                       type_l=type;      
                        var  size_x=(x-left)/100;
                        var  size_y=(y-top)/100;
                        var x_max=0;
                        var y_max=0;
                       time=setInterval(function(){
                            x_max+=size_x;
                            y_max+=size_y;
//                           console.info(y_max);
                           console.info(Math.round(x_max));
                        console.info(x-left);
                         console.info('-------');
                            $('.index-two-title').find('img').css({'left':parseInt(left)+parseInt(x_max)+'px','top':parseInt(top)+parseInt(y_max)+'px'});
                           
                           if(Math.round(x_max) ==(x-left) && Math.round(y_max) ==(y-top)){
                                clearInterval(time);
                                reload();
                           }
                       },10)
                   }
                    reload();
                   $('.index-two-title').find('img').eq(0).mouseenter(function(){
                        clearInterval(time);
                   })
                   $('.index-two-title').find('img').eq(0).mouseleave(function(){
                        reload();
                   })
        </script>




预览效果


http://static.prient.top/zhaoming/


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值