1 2 3 4 56 7 8 9 10 11 12 18 24 30 36 42 4852 53 54 55 56 *{ 57 padding:0px; 58 margin:0px; 59 font-family:"微软雅黑"; 60 } 61 a{ 62 text-decoration:none; 63 } 64 .ditem{ 65 width:220px; 66 height:352px; 67 border:solid 1px #ccc; 68 float:left; 69 margin:0px 5px; 70 font-size:14px; 71 margin-top:10px; 72 } 73 #dpros{ 74 width:750px; 75 } 76 .dprice{ 77 height:30px; 78 width:100%; 79 text-align:center; 80 color:#f00; 81 font-size:20px; 82 font-weight:900; 83 } 84 .dbtn a{ 85 margin-top:10px; 86 width:150px; 87 height:36px; 88 background-color:#ff6a00; 89 display:block; 90 text-align:center; 91 line-height:36px; 92 color:#fff; 93 font-size:20px; 94 margin:10px auto; 95 border-radius:12px; 96 } 97 #dcar{ 98 top:300px; 99 position:absolute;100 right:0px;101 width:72px;102 height:63px;103 background-image:url("../images/car.jpg");104 }105 #dprocount{106 width:20px;107 height:20px;108 background-color:#f00;109 color:#fff;110 font-size:12px;111 border-radius:100%;112 text-align:center;113 line-height:20px;114 }115 116 117 ///4951050118 var ipronum = 0;119 $(function () {120 $(".dbtn").click(function () {121 //$(this).find("a").css("background-color", "#ccc").parent().unbind("click");//只能添加一次购物车后禁用122 ipronum++;123 var addImg = $(this).parent().find(".dpic").find("img");//找到原始图片124 var cloneImg = addImg.clone();//克隆当前图片125 cloneImg.css({126 "width": "250px",//设置与原始图片大小一致127 "height": "250px",128 "position": "absolute",129 "top": addImg.offset().top,//offset()方法返回或设置匹配元素相对于文档的偏移(位置)130 "left": addImg.offset().left,131 "z-index":1000,//图片要显示在其他图片上面,要大于1132 "opacity":"0.5"//设置透明度133 });134 cloneImg.appendTo($("body")).animate({135 "width": "50px",136 "height": "50px",137 "top": $("#dcar").offset().top,138 "left": $("#dcar").offset().left,139 }, 1000, function () {140 $("#dprocount").html(ipronum);141 cloneImg.remove();//加完之后移除142 });143 });144 });