January 11, 200917 yr In jquery, how would i go about targeting multiple elements. For example, say i have 4 boxes. [a]____[c]__[d] And when i mouseover box [c] i want to apply an effect to boxes a,b and d But if i mouse over box [a] i want it to apply to b,c and d. How would i go about this? I've tried a few ideas i had, but they just plain and simple didn't work. I have a very bad habbit of overcomplicating things though, so would like some input. Suggestions, pointers, links, anything welcome
January 11, 200917 yr add them all in a div containing them give it class="container" each one has its own class $('div.container > div').hover(function() { var notHovered = $(div.container > div').not($(this).attr("class")); notHovered.slideTo(); // or whatever other effect you want to apply }); May not work, quick idea though =]
January 11, 200917 yr Author Thank you, that was a massive help now i've evolved it into this (please bear with me as i'm still a jquery noob/novice) $(window).bind('load', function () { $('div.case-study-list > a').hover(function() { var notHovered = $('div.case-study-list > a').not($(this).attr("class")); notHovered.fadeOut("3000"); // or whatever other effect you want to apply }); }); now that fades it out, but firebug flags up handler is undefined plus now i've got that to fade out, how do i get it to fade back in when the mouse is no longer hovering?
January 11, 200917 yr $(window).bind('load', function () { $('div.case-study-list > a').hover(function() { var notHovered = $('div.case-study-list > a').not($(this).attr("class")); notHovered.fadeOut("3000"); // or whatever other effect you want to apply }, function() { var notHovered = $('div.case-study-list > a').not($(this).attr("class")); notHovered.fadeIn("3000"); // or whatever other effect you want to apply }); }); That should do the trick
January 12, 200917 yr Author Almost there now, thank you. Starting to wish i found this forum sooner if everyone's as helpful as you i just hope iEntry never buy it. Anyway, that loops the animation, so how would i go about having it break after it's faded out, and another brake when it's faded back in?
January 13, 200917 yr Author Ok, i've been fiddling around with it, i've got the fade out for when the mouse is over it, and the fade back in for when the mouse leaves, but it's doing all of my images, not just the ones not hovered on.... Anyone help? $(window).bind('load', function () { $('div.case-study-list > a > img').hover(function() { var hover = $('div.case-study-list > a > img').not($(this).attr("class")); hover.animate({opacity: 0}, 250); // or whatever other effect you want to apply }, function() { $('div.case-study-list > a >img').not($(this).attr("class")); var notHovered = $('div.case-study-list> a > img'); notHovered.animate({opacity: 1}, 250); // or whatever other effect you want to apply }); });
January 14, 200917 yr Author Ok, i've got it pretty much fully working, there's just one minor thing i want to fix. Can anyone help me set it up so that if when it's triggered again it waits until the animation has finished, before starting the image on the next image? And for anyone who's interested, the working code is. $(window).bind('load', function () { $('div.case-study-list > a > img').hover(function() { var hover = $('div.case-study-list > a > img').not(this); hover.animate({opacity: 0}, 250); // or whatever other effect you want to apply }, function() { $('div.case-study-list > a >img'); var notHovered = $('div.case-study-list> a > img'); notHovered.animate({opacity: 1}, 250); // or whatever other effect you want to apply }); }); With this html <div id="case-study"> <div class="case-study-list"><a href="#" /><img src="image.jpg" alt="image description"></a></div> <div class="case-study-list"><a href="#" /><img src="image.jpg" alt="image description"></a></div> <div class="case-study-list"><a href="#" /><img src="image.jpg" alt="image description"></a></div> <div class="case-study-list"><a href="#" /><img src="image.jpg" alt="image description"></a></div> </div> <!-- end of case-study --> That's there for reference so it's had all my code stripped out except for what is actually needed for the effect ready if anyone should ever want to use this for there own work. It's been a good learning curve (first time i've actually done something myself with jquery), and thanks for your help.
February 2, 200917 yr So i added this to your code $(window).bind('load', function () { $('div.case-study-list > a > img').hover(function() { var hover = $('div.case-study-list > a > img').not(this);hover.stop().animate({opacity: .5}, 550); }, function() { $('div.case-study-list > a >img'); var notHovered = $('div.case-study-list> a > img');notHovered.stop().animate({opacity: 1}, 550); }); }); Is that the desired effect u were looking for? This little piece of java script has really helped me out on a personal project. Thank u so much!
February 2, 200917 yr Author I worked that out, should of updated it sorry. It was a good learning curve (: Wether it's done the best way or not i still don't know.... but i'm learning (:
Create an account or sign in to comment