Last active
December 29, 2015 12:29
-
-
Save glebcha/7670611 to your computer and use it in GitHub Desktop.
Simple "drop to cart" animation used for small shop and copied as is.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.toCart = function (options) { | |
var _settings = $.extend({ | |
duration: 1000, | |
callback: function () {} | |
}, options); | |
return this.each(function () { | |
var _ = $(this), | |
_target = $(_settings.target), | |
_clone = _.clone(false).height(_.height()); | |
_clone.insertAfter(_).fadeTo(_settings.duration); | |
_clone.css({ | |
position: 'absolute', | |
top: _.position().top + 'px', | |
left: _.position().left + 'px' | |
}).animate({ | |
top: (_target.position().top + _target.height()) - 45 + 'px', | |
left:_target.position().left+700+'px' | |
}, _settings.duration, 'swing', function () { | |
_clone.remove(); | |
_.fadeTo(1000, 1); | |
_settings.callback(); | |
}); | |
}); | |
}; | |
var dropCart = function () { | |
var = document.querySelectorAll('.cart-status'); | |
for (var i = 0; i < cartBtns.length; i++) { | |
var cartBtn = cartBtns[i]; | |
var transfer = function (event) { | |
event.preventDefault(); | |
if(/full-items-list/.test(this.parentNode.parentNode.className) !== true) { | |
$(this.parentNode.children[0].children[0]).toCart({ | |
target: '.cart-state', | |
orderByDataKey: 'string-data-value', | |
callback: function () {} | |
}); | |
} | |
}; | |
$(cartBtn).bind('click', transfer); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment