javascript - How can I stop queue animation jquery? -
i using function add or remove products favorites. when add or remove product favorites div pops out message. have problem queue animation.
does knows way fix this?
function addfavorite(code, action) { var website = 'http://localhost'; var cod = code; var action = action; var $this = $j(this); if (action == 'removefav') { $j.ajax({ type: 'post', url: '/ajax/handler.favorite.php?action=removefav', data: { 'cod': cod }, beforesend: function() { $j('.topmessage').show(); $j('.topmessage span').html('<img src="' + website + '/assets/loader.gif" alt="loading..">'); $j('.topmessage span').animate({ top: "+=80px", }, 500); }, success: function(data) { $j('.topmessage span').html(data); $j('.topmessage span').delay(3000).animate({ top: "-=80px", }, 500); } }); } if (action == 'addfav') { $j.ajax({ type: 'post', url: '/ajax/handler.favorite.php?action=addfav', data: { 'cod': cod }, beforesend: function() { $j('.topmessage').show(); $j('.topmessage span').html('<img src="' + website + '/assets/loader.gif" alt="loading..">'); $j('.topmessage span').animate({ top: "+=80px", }, 500); }, success: function(data) { $j('.topmessage span').html(data); $j('.topmessage span').delay(3000).animate({ top: "-=80px", }, 500); } }); } }
you can this: create function display messages , animate div.
function displayaddedmessage(message) { var span = $j('.topmessage span'); var addedmessage = span.parent(); var wrapper = addedmessage.parent(); addedmessage.css('top', -85).hide(); if (message) { span.html(message); } var clonedaddedmessage = addedmessage.clone(false); addedmessage.remove(); wrapper.prepend(clonedaddedmessage); clonedaddedmessage.show().delay(100).animate({ top: 10 }, 500).delay(3500).animate({ top: -100 }, 500); }
you can use function in:
function addfavorite(code, action) { var website = 'http://localhost'; var cod = code; var action = action; var $this = $j(this); if (action == 'removefav') { $j.ajax({ type: 'post', url: '/ajax/handler.favorite.php?action=removefav', data: { 'cod': cod }, beforesend: function() { $j('.topmessage').show(); displayaddedmessage('<img src="' + website + '/assets/loader.gif" alt="loading..">'); }, success: function(data) { $j('.topmessage span').html(data); displayaddedmessage(data); } }); } if (action == 'addfav') { $j.ajax({ type: 'post', url: '/ajax/handler.favorite.php?action=addfav', data: { 'cod': cod }, beforesend: function() { $j('.topmessage').show(); displayaddedmessage('<img src="' + website + '/assets/loader.gif" alt="loading..">'); }, success: function(data) { $j('.topmessage span').html(data); displayaddedmessage(data); } }); } }
Comments
Post a Comment