h5 添加购物车 动画效果实现 (贝塞尔曲线)

 <style>
    .shopBox{
        display: flex;
        justify-content: space-between;
        font-size: 1rem;
        margin-bottom: 20px;
        align-items: center;
        height:60px;
    }
    .shopTBox{
        display: flex;
        align-items: center;
    }
    .shopTBox .iPic{
        width: 5rem;
        height: 5rem;
        border-radius: 50%;
    }
    .carBox{
        position: fixed;
        left:50px;
        bottom:50px;
        width:100px;
        height:100px;
        background-color: pink;
        border-radius: 50%;
        z-index: 10;
    }
    .liACard{
        width:2rem;
        height:2rem;
        background-color: #4a90e1;
        color: #fff;
        font-size: 2rem;
        line-height: 1.7rem;
        text-align: center;
        border-radius: 50%;
    }
    .addTCar{
        position: fixed;
        top:0;
        left:0;
        line-height: 2rem;
        z-index:9;
        text-align: center;
        color: #fff;
        transition: 1s linear;
    }
    .addTCar .iconfont{
        width: 2rem;
        height: 2rem;
        background: #4a90e1;
        border-radius: 50%;
        display: block;
        transition: 1s cubic-bezier(0.5,-0.5,1,1);
    }
    .carBox.animate {
        animation: footer-car-animate 500ms ease-in-out;
    } 
    @keyframes footer-car-animate {
        0% {
            transform: scale(1);
        }
        25% {
            transform: scale(0.8);
        }
        50% {
            transform: scale(1.1);
        }
        75% {
            transform: scale(0.9);
        }
        100% {
            transform: scale(1);
        }
    }
</style>
<body>
    <div class="goodsList">
        
    </div>
    <div class="carBox"> 
    </div> 
    <script>
        var goods = [
            {
                title: 'huas' 
            },
            {
                title: 'df',
                
            },
            {
                title: 'zs',
                
            },
            {
                title: 'dt',
            
            },
            {
                title: 'db',
                
            }
        ];

        class UIGoods{
            constructor(g){
                this.data=g;
                this.choose=0;
            }
        }
        //整个界面的数据
        class UIData{
            constructor(){
                var uiGoods=[];
                for(var i=0;i<goods.length;i++){
                    var uig=new UIGoods(goods[i])
                    uiGoods.push(uig);
                }
                this.goodsContainer=document.querySelector('.goodsList')
                this.car=document.querySelector('.carBox')
                console.log(uiGoods);
                this.uiGoods=uiGoods;
                this.createHTML();
                this.listenEventer();
            }
            createHTML(){
                var html='';
                for(var i=0;i<this.uiGoods.length;i++){
                    var g=this.uiGoods[i];
                    html+=`
                    <div class="shopBox">
                        <div class="shopTBox">
                            <div>
                            </div>
                            <div>
                                ${g.data.title}
                            </div>   
                        
                        </div>
                        <div index="${i}" class="liACard">+</div>
                    </div>`
                }
                this.goodsContainer.innerHTML=html;
            }
            carAnimate(){
                this.car.classList.add('animate');
            }
            //监听各种事件
            listenEventer(){
                //监听购物车图标动画事件,结束后删除animate类dom
                this.car.addEventListener('animationend',function(){
                    this.classList.remove('animate');
                })
            }
            jump(index){
                console.log(this.goodsContainer.children[index]);
                var btnAdd=this.goodsContainer.children[index].querySelector('.liACard');
                var rect=btnAdd.getBoundingClientRect();
                var start={
                    x:rect.left,
                    y:rect.top
                }
                //获取购物车距离左侧,距离顶部的距离
                var carBox=document.querySelector('.carBox').getBoundingClientRect();
                console.log(carBox);
                var end={
                    x:carBox.left+carBox.width/2,
                    y:carBox.top
                }
                //创建动画添加购物车动画效果的盒子
                var div=document.createElement('div');
                div.className='addTCar';
                var i=document.createElement('i')
                i.className='iconfont';
                div.style.transform=`translateX(${start.x}px)`
                i.style.transform=`translateY(${start.y}px)`
                div.appendChild(i);
                document.body.appendChild(div)
                //强行渲染
                div.clientWidth;
                //设置结束位置
                div.style.transform=`translateX(${end.x}px)`
                i.style.transform=`translateY(${end.y}px)`
                div.addEventListener('transitionend',()=>{
                    console.log('动画触发了');
                    div.remove();          
                    this.carAnimate();  

                },{
                    once:true
                })
            }
        }
        
        let zhi=new UIData();
        // //监听点击事件
        // var ui=new UI();
        zhi.goodsContainer.addEventListener('click',function(e){
            console.log(e.target.classList);
            //判断goodsListDom下的class中是否包含liACard属性 
            if(e.target.classList.contains('liACard')){
                var index=+e.target.getAttribute('index')
                zhi.jump(index);
            }
        }) 
    </script>
</body>

本课程讲了Vue3+Vue2+Uni-app(uniapp)入门基础与实战,其中还重点讲解了ES6、TypeScript这些基础知识,实战由两大价值5000元的真实企业级项目组成,分别是仿京东电商网站和仿美团微信点餐小程序,同时两大项目代码全部赠送,还赠送前后端架构模板,工作中直接使用。VUE和uni-app是目前热门的前端框架,本课程教你如何快速学会VUE和uni-app并应用到实战,教你如何解决内存泄漏,常用UI库的使用,自己封装组件和插件,正式上线白屏问题,性能优化、解决iphoneX“刘海”兼容性问题、微信支付、微信授权登录,获取位置在地图上显示,获取用户所在的城市和街道信息,微信小程序发布审核等。对正在工作当中或打算学习VUE和uni-app高薪就业的你来说,那么这门课程便是你手中的葵花宝典。学习技巧:学习当中不要只看,一定要多敲代码,如果碰到某一个知识点不是很明白,不要钻牛角尖,千万不要因为一个点,放弃整个森林,接着往下学,硬着头皮开发项目。只要能亲自开发一个完整的项目,你会发现不明白的地方自然而然就明白了,项目做出来就真正的学会了。此vue和uni-app课程以面试和实战为基础进行讲解,每个知识点都会让你知道在实际项目开发中如何使用,学习后,可以开发大型项目,增强逻辑思维,至少让你拥有3年以上开发经验的实力!代码和ppt均可下载!免费提供《企业级完整实战项目接口文档》,绝对可用
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

路光.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值