购物车水平抛物线动画

效果:



<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
    <meta content="telephone=no" name="format-detection" />
    <title>CSS3 水平抛物线动画</title>
    <script>
      ! function(n) {
        var e = n.document,
          t = e.documentElement,
          i = 750,
          d = i / 100,
          o = "orientationchange" in n ? "orientationchange" : "resize",
          a = function() {
            var n = t.clientWidth || 320;
            n > 750 && (n = 750), t.style.fontSize = n / d + "px"
          };
        e.addEventListener && (n.addEventListener(o, a, !1), e.addEventListener("DOMContentLoaded", a, !1))
      }(window);
    </script>
    <style type="text/css">
      *{
        padding: 0;
        margin: 0;
      }
      .main{

      }
      .product{

      }
      .product ul li{
        font-size: 0.3rem;
        position: relative;
        height: 1rem;
      }
      .product ul li:after{
        content: '';
        position: absolute;
        left: 0;
        bottom: 0;
        width: 100%;
        height: 1px;
        border-bottom: 1px solid #eeeeee;
      }
      .product ul li .buy{
        position: absolute;
        top: 0.23rem;
        right: 0.3rem;
        font-size: 0.3rem;
        border: 1px solid #ed2e40;
        color: #ed2e40;
        border-radius: 0.1rem;
        padding: 0 0.1rem;
        height: 0.5rem;
        line-height: 0.5rem;
      }
      .buyCar{
        position: fixed;
        bottom: 0.5rem;
        left: 0.5rem;
        font-size: 0.2rem;
        width: 0.8rem;
        text-align: center;
        height: 0.8rem;
        line-height: 0.8rem;
        border-radius: 50%;
        background-color: #ed2e40;
        color: #fff;
        z-index: 3;
      }
      #ball {
        width:12px;
        height:12px;
        background: #5EA345;
        border-radius: 50%;
        position: fixed;
        z-index: 2;
        bottom: 0.6rem;
        left: 0.6rem;
      }
    </style>
  </head>
  <body>
  <div class="main">
    <div class="product">
      <ul id="ul">
        <li><div class="con"></div><span class="buy" οnclick="buy()">购买</span></li>
      </ul>
    </div>
    <div class="buyCar">购物车</div>
    <!--<div id="ball"></div>-->
  </div>
  <script>
      //生成HTML标签
      document.getElementById('ul').innerHTML='';
      for(var i=0;i<15;i++){
          var newLi = document.createElement("li");
          newLi.innerHTML = '<li><div class="con">'+(i+1)+'</div><span class="buy" οnclick="buy(this)">购买</span></li>';
          document.getElementById('ul').appendChild(newLi)
      }
      //生成水平抛物线动画 var ball=parabolic();   ball(e); //传入点击标签
      function parabolic() {
          return function (e) {
              //生成动画标签
              var ball = document.createElement("div");
              ball.id = 'ball';
              document.body.appendChild(ball);

              var rect = e.getBoundingClientRect(); //getBoundingClientRect获得页面中某个元素的左,上,右和下分别相对浏览器视窗的位置。
              ball.style.top = (rect.top+rect.height/2)+'px';
              ball.style.left = rect.left+'px';
              ball.style.transition = 'left 0s, top 0s';
              //获取购物车标签
              var buyCar=document.getElementsByClassName('buyCar')[0].getBoundingClientRect();
              setTimeout(()=>{
                  ball.style.top = window.innerHeight-(window.innerHeight-buyCar.top-buyCar.height/2)+'px';
                  ball.style.left = (buyCar.left+buyCar.height/2)+'px';
                  ball.style.transition = 'left 1s linear, top 1s ease-in';
              }, 20)
              //动画结束后自动删除
              setTimeout(function () {
                  document.body.removeChild(ball);
              },1050)
          }
      }
      //
      function buy(e) {
          var ball=parabolic();
          ball(e);
      }
  </script>
  </body>
</html>







js加入购物车抛物线动画购物车效果特效,亲测可用, 当您在电商购物网站浏览中意的商品时,您可以点击页面中的“加入购物车”按钮即可将商品加入的购物车中。本文介绍借助一款基于jQuery的动画插件,点击加入购物车按钮时,实现商品将飞入到右侧的购物车中的效果。 HTML 首先载入jQuery库文件和jquery.fly.min.js插件。 复制代码 代码如下: 接着,将商品信息html结构布置好,本例中,我们用四个商品并排布置,每个商品box中包括有商品图片、价格、名称以及加入购物车按钮等信息。 复制代码 代码如下: ¥3499.00 LG 49LF5400-CA 49寸IPS硬屏富贵招财铜钱设计 加入购物车 ¥3799.00 Hisense/海信 LED50T1A 海信电视官方旗舰店 加入购物车 ¥¥3999.00 Skyworth/创维 50E8EUS 8核4Kj极清酷开系统智能液晶电视 加入购物车 ¥6969.00 乐视TV Letv X60S 4核1080P高清3D安卓智能超级电视 加入购物车 然后,我们还需要在页面的右侧加上购物车以及提示信息。 复制代码 代码如下: 购物车 已成功加入购物车! CSS 我们使用CSS先将商品排列美化,然后设置右侧购物车样式,具体请看代码: 复制代码 代码如下: .box{float:left; width:198px; height:320px; margin-left:5px; border:1px solid #e0e0e0; text-align:center} .box p{line-height:20px; padding:4px 4px 10px 4px; text-align:left} .box:hover{border:1px solid #f90} .box h4{line-height:32px; font-size:14px; color:#f30;font-weight:500} .box h4 span{font-size:20px} .u-flyer{display: block;width: 50px;height: 50px;border-radius: 50px;position: fixed;z-index: 9999;} .m-sidebar{position: fixed;top: 0;right: 0;background: #000;z-index: 2000;width: 35px;height: 100%;font-size: 12px;color: #fff;} .cart{color: #fff;t
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值