jquery - One Page fadeIn & fadeOut Transition Logic -


i making one-page website client. there 3 different menu groups, in example simplified 1 menu , less content.

i have navigation:

 <nav> <ul id="main" class="toggle"> <li><a id="design" href="#">design</a></li> <li><a id="contactus" href="#">contact us</a></li> <li><a id="aboutus" href="#">about us</a></li> <li><a id="news" href="#">news</a></li> </ul> </nav> 

and divs below:

<div class="designcontent"> design content here </div> <div class="aboutuscontent"> content here </div> 

so if click on design show designcontent, , if click show aboutuscontent , on.

i asking short-hand code of

 $("#design").click(function(){ $('.homecontent').fadeout(500); $('.designcontent').delay(500).fadein(1000); return false; }); $("#home").click(function(){ $('.designcontent').fadeout(500); $('.homecontent').delay(500).fadein(1000); return false; }); 

because gets more , more complicated if there many pages, , if client wants add new page.

i have jquery code below id's , use them in array , hide contents on load:

$('#main li a').each(function(){ liids.push('.'+ $(this).attr('id')+'content'); $(''+liids).hide(); }) 

what missing is, clicking on menu links , showing correct content each time menu clicked.

i hope question clear enough, if not can provide visual examples on jsfiddle.

thanks taking time read question

my problem solved using:

$("a").click(function(){ var cls = $(this).attr('id') $('.' + cls + 'content').addclass('onpage'); $('.onpage').fadeout(500); $('.' + cls + 'content').delay(500).fadein(1000); return false; }) 

you can use similar name id of anchor , it's target element's class:

html:

<li><a id="design" href="#">design</a></li> <div class="design content"> design content here </div> 

js:

$("ul li a").click(function(){ var cls = $(this).attr('id') $(".content").fadeout(500); $('.' + cls).delay(500).fadein(1000); return false; }) 

demo


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -