I created a fiddle to demonstrate my problem: http://jsfiddle.net/motocomdigital/QyhpX/5/
Overview
I am creating a tabbed website using jQuery .animate function. Which on my live site seems like a glitch on the first rotation, but I canβt play it in the violin.
The left tab animates the correct positioning of the div#wrapper to -170px and back to 0 - then I added .removeAttr('style'); to remove the style attribute so that it does not interfere with the right tab.
On the right tab, div#wrapper animates left positioning to -170px and back to 0 - then I added .removeAttr('style'); to remove the style attribute so that it does not interfere with the left tab.
PROBLEM
.removeAttr('style'); does not remove the inline style attribute after .animate completes, which is why my left tab will be dysfunctional if the right tab is open.
See jsfiddle http://jsfiddle.net/motocomdigital/QyhpX/5/
Also, did anyone notice any crashes when opening the first tab the first time? Left or right? It seems that it hangs on the first opening, and then suddenly opens, but gradually closes and then smoothly opens. Its just the first click.
TAB CODE SCRIPT
var $tabLeft = $(".tab-left-button span"), $tabRight = $(".tab-right-button span"), $siteSlide = $("#wrapper"); $tabLeft.on('click', function () { if ($tabLeft.html() == 'X' ) { $siteSlide.stop().animate({ right: "0" }, 300); $tabLeft.html('Tab Left'); return false; $siteSlide.removeAttr('style'); } else { $siteSlide.stop().animate({ right: "-170px" }, 300); $tabLeft.html('X'); $('body,html').animate({ scrollTop: 0 }, 800); } }); $tabRight.on('click', function () { if ($tabRight.html() == 'X' ) { $siteSlide.stop().animate({ left: "0" }, 300); $tabRight.html('Tab Right'); return false; $siteSlide.removeAttr('style'); } else { $siteSlide.stop().animate({ left: "-170px" }, 300); $tabRight.html('X'); $('body,html').animate({ scrollTop: 0 }, 800); } });
Any help would be greatly appreciated. Thanks
http://jsfiddle.net/motocomdigital/QyhpX/5/