|
|
#1 | |
|
Minor issue with jQuery function
Hey guys, been working on a jQuery code blurb that's a very simple show/hide system and I could use a bit of help. Clicking a button on the menu shows the graphic associated with that menu item while hiding the one previously visible. Example is here.
The code is pretty simple in general, here's the exciting part: Quote:
The issue I'm having is that if a button is clicked to show an image and then clicked again before another menu item is clicked, it hides that image without showing another. Any suggestions on how to manage that second click so that the image isn't hidden? Thanks. |
||
|
|
0
|
|
|
#2 |
|
For each click function you could add an if statement to check the display of the image and if it's display:none then perform the fade and hides. Something like:
Code:
$('.showhide_image01').click(function(){
if( $(".image01").css("display") == "none" ){
$(".image01").fadeToggle();
$(".image02").hide();
$(".image03").hide();
$(".image04").hide();
$(".image05").hide();
}
});
__________________
Mac Mini, 2.3ghz i7, 16GB RAM, 1TB HDD, ML | MacBook Air 13", 1.3ghz i5, 1GB RAM, 128GB SSD, ML | iPhone 5 32GB White | iPad 3 64GB Black
|
|
|
|
1
|
|
|
#3 |
|
Awesome, I'll try that out. Thanks!
|
|
|
|
0
|
|
|
#4 |
|
Assuming that all the buttons will be children of a common ancestor, I'd look at event delegation and have a single handler attached to the ancestor. The handler would hide all the images then show the targeted image.
Some rough code: Code:
var imgs = $('parent > img');
imgs.hide().filter(':first').show();
$('div.buttons a').click(function () {
imgs.hide();
imgs.filter(this.hash).show();
$('div.buttons a').removeClass('selected');
$(this).addClass('selected');
return false;
}).filter(':first').click();
|
|
|
|
0
|
|
|
#5 |
|
That's a bit more involved then I was planning to get at this point (and I do realize my code could be much more efficient) but I'll dig more into that when I have time.
Appreciate the advice, thanks! |
|
|
|
0
|
|
|
#6 |
|
Codepen.io example for fig
Hey fig,
A little example I whipped up, hope it helps you out. I used CSS3 transition for the fading but you could easily swap it out for a jQuery animate if you need an IE<9 fix. http://codepen.io/ipaintcode/pen/CDjku If you have any questions feel free =) |
|
|
|
1
|
|
|
#7 | |
|
Quote:
I'll dig into this a bit and see if I can follow what's going on, greatly appreciate it! |
||
|
|
0
|
|
|
#8 |
|
Updated
Hey Fig,
Swapped it over to non CSS3 transition. It's fully functional but was more or less pseudo code but demonstrates what you need. http://codepen.io/ipaintcode/pen/CDjku |
|
|
|
1
|
|
|
#9 |
|
Brilliant. Thanks, greatly appreciate it!
|
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 08:34 PM.








Linear Mode
