加入购物车动画特效

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>加入购物车动画特效</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f5f5f5;
            color: #333;
            padding: 20px;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }
        
        h1 {
            text-align: center;
            margin-bottom: 40px;
            color: #333;
        }
        
        .products {
            display: flex;
            flex-wrap: wrap;
            gap: 30px;
            justify-content: center;
        }
        
        .product {
            background: white;
            border-radius: 10px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.1);
            overflow: hidden;
            width: 280px;
            transition: transform 0.3s ease;
            position: relative;
        }
        
        .product:hover {
            transform: translateY(-10px);
            box-shadow: 0 10px 20px rgba(0,0,0,0.15);
        }
        
        .product-image {
            height: 200px;
            overflow: hidden;
            position: relative;
        }
        
        .product-image img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            transition: transform 0.5s ease;
        }
        
        .product:hover .product-image img {
            transform: scale(1.05);
        }
        
        .product-info {
            padding: 20px;
        }
        
        .product-title {
            font-size: 18px;
            margin-bottom: 10px;
            color: #333;
        }
        
        .product-price {
            font-size: 22px;
            font-weight: bold;
            color: #e74c3c;
            margin-bottom: 15px;
        }
        
        .add-to-cart {
            display: block;
            width: 100%;
            padding: 12px;
            background: linear-gradient(to right, #3498db, #2ecc71);
            color: white;
            border: none;
            border-radius: 5px;
            font-size: 16px;
            cursor: pointer;
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
        }
        
        .add-to-cart:hover {
            background: linear-gradient(to right, #2980b9, #27ae60);
        }
        
        .add-to-cart:active {
            transform: scale(0.98);
        }
        
        .cart-icon {
            position: fixed;
            top: 20px;
            right: 20px;
            background: #e74c3c;
            color: white;
            width: 50px;
            height: 50px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 20px;
            box-shadow: 0 3px 10px rgba(0,0,0,0.2);
            z-index: 100;
        }
        
        .cart-count {
            position: absolute;
            top: -5px;
            right: -5px;
            background: #2ecc71;
            color: white;
            width: 25px;
            height: 25px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 12px;
            font-weight: bold;
        }
        
        /* 动画元素 */
        .animate-to-cart {
            position: absolute;
            width: 30px;
            height: 30px;
            background: rgba(46, 204, 113, 0.8);
            border-radius: 50%;
            pointer-events: none;
            z-index: 99;
            animation: flyToCart 1s ease-in-out forwards;
        }
        
        @keyframes flyToCart {
            0% {
                transform: scale(1);
                opacity: 1;
            }
            50% {
                transform: scale(0.5);
                opacity: 0.8;
            }
            100% {
                transform: scale(0.1);
                opacity: 0;
                top: 20px;
                left: calc(100% - 70px);
            }
        }
        
        /* 提示信息 */
        .notification {
            position: fixed;
            top: 80px;
            right: 20px;
            background: rgba(46, 204, 113, 0.9);
            color: white;
            padding: 15px 25px;
            border-radius: 5px;
            box-shadow: 0 3px 10px rgba(0,0,0,0.2);
            transform: translateX(200%);
            transition: transform 0.3s ease;
            z-index: 100;
        }
        
        .notification.show {
            transform: translateX(0);
        }
        
        /* 参考文章 */
        .reference {
            margin-top: 50px;
            padding: 20px;
            background: white;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
            text-align: center;
        }
        
        .reference a {
            color: #3498db;
            text-decoration: none;
            word-break: break-all;
        }
        
        .reference a:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>精选商品</h1>
        
        <div class="products">
            <!-- 商品1 -->
            <div class="product">
                <div class="product-image">
                    <img src="https://via.placeholder.com/300x200?text=商品1" alt="商品1">
                </div>
                <div class="product-info">
                    <h3 class="product-title">高端智能手机</h3>
                    <div class="product-price">¥3999</div>
                    <button class="add-to-cart" data-product="1">加入购物车</button>
                </div>
            </div>
            
            <!-- 商品2 -->
            <div class="product">
                <div class="product-image">
                    <img src="https://via.placeholder.com/300x200?text=商品2" alt="商品2">
                </div>
                <div class="product-info">
                    <h3 class="product-title">无线蓝牙耳机</h3>
                    <div class="product-price">¥599</div>
                    <button class="add-to-cart" data-product="2">加入购物车</button>
                </div>
            </div>
            
            <!-- 商品3 -->
            <div class="product">
                <div class="product-image">
                    <img src="https://via.placeholder.com/300x200?text=商品3" alt="商品3">
                </div>
                <div class="product-info">
                    <h3 class="product-title">智能手表</h3>
                    <div class="product-price">¥1299</div>
                    <button class="add-to-cart" data-product="3">加入购物车</button>
                </div>
            </div>
            
            <!-- 商品4 -->
            <div class="product">
                <div class="product-image">
                    <img src="https://via.placeholder.com/300x200?text=商品4" alt="商品4">
                </div>
                <div class="product-info">
                    <h3 class="product-title">笔记本电脑</h3>
                    <div class="product-price">¥6999</div>
                    <button class="add-to-cart" data-product="4">加入购物车</button>
                </div>
            </div>
        </div>
        
        <!-- 购物车图标 -->
        <div class="cart-icon">
            🛒
            <span class="cart-count">0</span>
        </div>
        
        <!-- 提示信息 -->
        <div class="notification">
            商品已成功加入购物车!
        </div>
        
    </div>

    <!-- 引入jQuery库 -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    
    <script>
        $(document).ready(function() {
            let cartCount = 0;
            
            // 加入购物车按钮点击事件
            $('.add-to-cart').click(function(e) {
                e.preventDefault();
                
                // 获取按钮位置
                const button = $(this);
                const buttonPos = button.offset();
                
                // 创建动画元素
                const animateElement = $('<div class="animate-to-cart"></div>');
                $('body').append(animateElement);
                
                // 设置动画元素初始位置
                animateElement.css({
                    'top': buttonPos.top + button.outerHeight() / 2 - 15,
                    'left': buttonPos.left + button.outerWidth() / 2 - 15
                });
                
                // 开始动画
                setTimeout(function() {
                    animateElement.remove();
                    
                    // 更新购物车数量
                    cartCount++;
                    $('.cart-count').text(cartCount);
                    
                    // 显示提示信息
                    const notification = $('.notification');
                    notification.addClass('show');
                    
                    setTimeout(function() {
                        notification.removeClass('show');
                    }, 2000);
                    
                    // 这里可以添加实际的加入购物车逻辑
                    const productId = button.data('product');
                    console.log('加入购物车的商品ID:', productId);
                    
                }, 1000);
                
                // 按钮点击效果
                button.addClass('active');
                setTimeout(function() {
                    button.removeClass('active');
                }, 200);
            });
            
            // 购物车图标点击事件
            $('.cart-icon').click(function() {
                alert(`当前购物车中有 ${cartCount} 件商品`);
            });
        });
    </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
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值