- /*
- * jquery―shopping 0.1
- * Copyright (c) 2014
- * 使用Jquery―shopping可以很方便的实现加入购物车效果
- */
- ;(function($){
- $.extend($.fn,{
- shoping:function(options){
- var self=this,
- $shop= $(options.car_obj || '.J-shoping'); //购物车位置
- var S={
- init:function(){
- //$(self).data('click',true).live('click',this.addShoping);
- $(self).on('click',this.addShoping);
- },
- addShoping:function(e){
- e.stopPropagation();
- var $target=$(e.target),
- //id=$target.attr('id'),
- //dis=$target.data('click'),
- img_src = $target.attr('p_img'),
- x = $target.offset().left + 30,
- y = $target.offset().top + 10,
- X = $shop.offset().left+$shop.width()/2-$target.width()/2+10,
- Y = $shop.offset().top;
- var $floatOrder_obj=$('<div style="width:50px;height:50px;padding:2px;background:#fff;border:solid 5px #e54144;overflow:hidden;position:absolute;z-index:890;"><img src="'+ img_src +'" width="50" height="50" /></div>');
- $('body').append($floatOrder_obj);
- //if(!$floatOrder_obj.is(':animated')){
- $floatOrder_obj.CSS({'left': x,'top': y}).animate({'left': X,'top': Y-80},500,function() {
- $floatOrder_obj.stop(false, false).animate({'top': Y-40,'opacity':0},500,function(){
- $floatOrder_obj.fadeOut(300,function(){
- $floatOrder_obj.remove();
- //$target.data('click',false).addClass('dis-click');
- });
- });
- });
- //}
- }
- };
- S.init();
- }
- });
- })(jQuery);
- //该片段来自于http://www.codesnippet.cn/detail/3012201411423.html
来源: http://www.codesnippet.cn/detail/3012201411423.html