点击飞入购物车效果

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8" />

<title>点击飞入购物车效果</title>

<script src="jquery-1.9.1.min.js"></script>

<script> 

$(document).ready(function(){ 

    $(".run").click(function(){ 

        var menID =  $(this).attr("id");

        var thisTop = $("#img_" + menID).offset().top; //所在位置的高度

        var thisLeft = $("#img_" + menID).offset().left; //所在位置的宽度

         animatenTop(thisTop,thisLeft);

        return false; 

    }); 

}); 

function animatenTop(thisTop,thisLeft) {

    var CopyDiv = '<img src="download.png" id="box" style="top:' + thisTop + 'px;left:' + thisLeft + 'px" />';

    var topLength =  $(".shopMenu li").offset().top; //取得到购物车的宽度

    var leftLength = $(".shopMenu li").offset().left; //取得到购物车的宽度 

    $("body").append(CopyDiv);

    $("body").children("#box").animate({width: "30px",height: "30px","top": topLength, "left": leftLength, "opacity": .1  }, 900, function(){$(this).remove()});

}

</script>

<style type="text/css">

body{

    font-family: "宋体",Arial;

}

ul{

    margin: 0;

    padding: 0;

    list-style:none;

}

.Listbox {

    width:150px;

    border:1px solid #ccc;

    margin-left: 100px;

}

.Listbox li {

    width:150px;

    text-align: center;

}

.shopMenu {

    border:1px solid #ccc;

    width:150px;

    margin-left: 500px;

    text-align: center;

}

.shopMenu{

    margin: 0;

    padding: 0;

    margin:200px 0 0 150px;

}

.shopMenu li{

    text-align: center;

    width: 150px;

    height: 150px;

    line-height: 150px;

}

#box {

    height: 120px;

    width: 126px;

    position: absolute;

}

</style>

</head>

<body>

<ul class="Listbox">

    <li>

        <img src="pic.png" width="100" id="img_1" />

    </li>

    <li><a href="#" class="run" id="1">click me</a></li>

</ul>

<ul class="shopMenu">

    <li>空盒</li>

</ul>

</body>

</html>

转载于:https://www.cnblogs.com/piuba/p/3449564.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值