javascript - jQuery Traversing and simple code? -


okay, before ask question. let me explain goal: want write little code possible, , still able have tons of functionality @ same time. have coined 'beautiful code' myself , colleagues.

here's problem: want click box, , panel fade in desired content based on box clicked. except cant use 2 classes , cannot re-use id's.

here's code: http://jsfiddle.net/2yr67/

$('.maingrid').click(function(){     //'maingrid' fade out     //'panel' fade in proper content }); 

i had 2 ideas please me.

a) have 1 panel fade in, , content fill panel based on 'maingrid' box 'click'ed b) have specific panel content fade in, based on 'maingrid' selected

i'm not asking me, push me towards syntax needed want

thanks in advance!

the first thing move panel html elements closer maingrid elements. allows hide/show correct elements in order. having of panels in own separate element causes dom manipulation should shouldn't need do. simplicity, put each panel right after maingrid element associated it.

html structure

<div class=".maincontainer">    <div class='maingrid'></div>    <div class='panel'></div>    <div class='maingrid'></div>    <div class='panel'></div>    <div class='maingrid'></div>    <div class='panel'></div>    <div class='maingrid'></div>    <div class='panel'></div> </div> 

i added panel class have same css maingrid, make invisible @ start:

.maingrid, .panel {     height: 345px;     width: 345px;     float: left;     /* [disabled]background-color: #000; */     margin-top: 5px;     margin-right: 5px;     cursor: pointer;     overflow: hidden; } .panel{     display:none;     color:white;  } 

this fade out current element clicked , fade in next panel element.

$('.maingrid').click(function(){         var $that = $(this);         $(this).fadeout(function(){  //this wait until fadeout done before attempting fadein.             $that.next().fadein();         });     });     $('.panel').click(function(){         var $that = $(this);         $(this).fadeout(function(){             $that.prev().fadein();         });     });  

there seems bug hover not show text on first hover event.

jsfiddle: http://jsfiddle.net/mdjfe/


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -