美文网首页
添加商品到购物车动画

添加商品到购物车动画

作者: 我怎么可能不是我 | 来源:发表于2017-09-05 09:42 被阅读0次

添加商品到购物车的动画,网上很多是用的抛物线的思想来做,这是一种很好的思想,网上也有很多的demo和介绍,这里我介绍另一种方法,一种直线运动,实现起来很方便的方法。

主要思路

1,当点击‘加入购物车’的时候获取被点击按钮的‘坐标1’;
2,在当前坐标位置创建动画节点,;
3,获取目标节点(购物车位置)‘坐标2’;
4,使用jQuery的animate函数,把动画加点从‘坐标1’想‘坐标2’移动

这样做是直线运动,是不是so easy,话不多说,上代码

<!DOCTYPE html>
<html>
<head>
<meta http-equiv=content-type content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<link rel="stylesheet" href="css/index.css">
<title>购物车添加动画</title>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<!--页面样式-->
<style>
*{margin: 0;padding: 0;}
ul{list-style:none}
.body{width: 80%;height: 100vh;background-color:rgba(23,23,23,0.1);margin:0 auto;}
.car{width: 80%;height: 40vh;background-color:grey;margin:0 auto;display:
        flex;justify-content: flex-end}
.goods{width: 80%;height: 60vh;background-color:white;margin:0 auto;}
.car>p{display: flex;width: 80px;height: 80px;border-radius: 40px;background-color:
        yellowgreen;justify-content: center;  flex-direction:column;}
.car>p>span{margin: auto}
.goodsul{display: flex;flex-wrap: wrap}
.goodsul>li{width: 100px;height: 200px;border:grey solid 1px;display: flex;justify-content:
        center;flex-direction: column;margin:10px}
.goodsul>li>a{margin:auto;text-decoration: none;display: block;width: 90%;height: 32px;line-height:
        32px;background-color: green;color: white;text-align: center}
</style>
</head>
<body>

<!--文档结构-->
<div class="body">
  <div class="car"><p class="shopcar"><span>购物车</span></p></div>
  <div class="goods">
    <ul class="goodsul">
      <li class="goodsul"><a class="goodson" href="javascript:" >加入购物车</a></li>
      <li class="goodsul"><a class="goodson" href="javascript:" >加入购物车</a></li>
      <li class="goodsul"><a class="goodson" href="javascript:" >加入购物车</a></li>
      <li class="goodsul"><a class="goodson" href="javascript:" >加入购物车</a></li>
      <li class="goodsul"><a class="goodson" href="javascript:" >加入购物车</a></li>
      <li class="goodsul"><a class="goodson" href="javascript:" >加入购物车</a></li>
  </ul>
</div>
</div>
<script>


//创建动画主体节点
function createplane(orL,orT) {
    var createele = document.createElement('div');
    createele.setAttribute("class","goodsone");
    createele.style.position = 'absolute';
    createele.style.width = '50px';
    createele.style.height = '50px';
    createele.style.backgroundColor = 'red';
    createele.style.left = orL+'px';
    createele.style.top = orT+'px';
    createele.style.borderRadius = '25px';
    document.body.appendChild(createele);
}

//    点击事件
$(".goodson").click(function () {
//        获取源位置(加入购物车按钮)坐标
    var orL = $(this).offset().left;
    var orT = $(this).offset().top;
    //  获取目标(购物车)坐标
    var obL = $(".shopcar").offset().left;
    var obT = $('.shopcar').offset().top;
    createplane(orL,orT);
    $(".goodsone").animate({"left":obL+10+"px","top":obT+10+"px"},1000,function () {
        $(this).remove();
    });
})
</script>
</body>
</html>

相关文章

  • 添加商品到购物车动画

    添加商品到购物车的动画,网上很多是用的抛物线的思想来做,这是一种很好的思想,网上也有很多的demo和介绍,这里我介...

  • Swift添加商品到购物车动画

    点击cell里+按钮加到右上角圆图购物车。 效果图如下: 代码如下: 重要点记录: 在当前路径中追加一条二阶贝塞尔...

  • Android端 仿饿了么点餐页面

    已实现的功能 * 顶部嵌套滑动逻辑 * 分类和商品级联定位 * 添加购物车动画 * 购物车弹窗 * 点击商品后的上...

  • 8.购物车管理

    购物车管理模块是属于用户侧模块,主要有7个接口:添加商品到购物车、更新购物车商品数、移除购物车商品、查看购物车当中...

  • 添加购物车

    商品添加购物车; 先判断当前用户购物车是否存在该商品,若存在就更新当前用的购物车商品数量,若不存在,则新增该商品到...

  • 贝塞尔曲线的应用(二)

    购物车添加商品实现轨迹动画 先看下实现效果 分析下实现原理,起始点是添加按钮,购物车是结束点,我们把控制点的x坐标...

  • 加入购物车动画效果实现

    不知道大家有没有发现,主流的电商类APP添加商品到购物车时,都会伴随一个小的“添加”动画。你有没有想过它是怎么实现...

  • 购物车动画

    今天整理一下购物车动画,整理一下,方便以后使用.咱们定外卖的的时候,添加商品,可以看一个加入购物车的动画,下面就实...

  • 解决jquery animate动画效果出现的抖动

    起因:在做鼠标滑过商品缩略图,弹出“添加购物车”按钮的动画效果时,出现了动画闪烁的问题,后来发现是animate重...

  • Django+Vue打造购物网站(八)

    购物车、订单管理和远程调试 添加商品到购物车 trade/serializers.py trade/views.p...

网友评论

      本文标题:添加商品到购物车动画

      本文链接:https://www.haomeiwen.com/subject/jgxujxtx.html