html - Animating css tabs using jquery -
i have css tabs,i trying fadein effect when tab clicked
i found 1 tutorial on web animate css tabs,however dont want change css,etc.i copy pasted jquery code , made necessary changes
here have tried far http://jsfiddle.net/mczv9/8/
the issue is,when reclick tabs,the content disappears.can me please.
here code
html
<!doctype html> <ul class="tabs clearfix"> <li><a href="#html" class="current">html</a> </li> <li><a href="#javascript">javascript</a> </li> <li><a href="#css">css</a> </li> </ul> <div class="content"> <div class="current" id="html">grtgrtgrtg</div> <div id="javascript">erfefr</div> <div id="css"> <p>similar the css used style tooltip, or info box.</p> </div> </div>
jquery
function resettabs() { $(".content > div").hide(); //hide content $(".tabs a").attr("class", ""); //reset id's } var myurl = window.location.href; //get url var myurltab = myurl.substring(myurl.indexof(".")); // localhost/tabs.html#tab2, myurltab = .tab2 var myurltabname = myurltab.substring(0, 4); // above example, myurltabname = #tab (function () { $(".content > div").hide(); // hide content $(".tabs li:first a").attr("class", "current"); // activate first tab $(".content > div:first").fadein(); // show first tab content $(".tabs a").on("click", function (e) { e.preventdefault(); if ($(this).attr("id") == "current") { //detection current tab return } else { resettabs(); $(this).attr("class", "current"); // activate $($(this).attr('name')).fadein(); // show content current tab } }); (i = 1; <= $(".tabs li").length; i++) { if (myurltab == myurltabname + i) { resettabs(); $("a[name='" + myurltab + "']").attr("id", "current"); // activate url tab $(myurltab).fadein(); // show url tab content } } })()
can me please.
i've updated code , works now:
(function () { $(".tabs a").on("click", function(e) { e.preventdefault(); var hash = $(this).attr('href'); window.location.hash = 'tab-' + hash.replace('#', ''); if ($(this).hasclass("current")) { //detection current tab return; } else { $(".content > div").hide(); $(".tabs a").removeclass("current"); $(this).addclass("current"); // activate $(hash).fadein(); // show content current tab } }); $(".tabs li:first a").trigger('click'); // activate first tab if(window.location.hash != ''){ $('.tabs a[href="'+window.location.hash.replace('tab-', '')+'"]').trigger('click'); } })();
here's updated example: http://jsfiddle.net/mczv9/14/
Comments
Post a Comment