Multiple or separate rollovers using Jquery. Mock up for a better explanation
UPDATED: 06.29.10 Here's the code I'm using so far. I'm really close after searching through the Jquery documentation.
$(document).ready(function(){
//Rollovers for circle buttons
$('img').hover(
function(){
this.src = this.src.replace("_org","_over");
},
function(){
开发者_JS百科 this.src = this.src.replace("_over","_org");
});
//Disjointed rollover - on hover make circles use secondary hover (over2)
$(".genBtn80").hover(
function(){
$(".gen80circle").src = $(".gen80circle").src.replace("_org","_over2");
},
function(){
$(".gen80circle").src = $(".gen80circle").src.replace("_over2","_org");
});
});
So I have everything working regarding the rollovers. I have the images suffixed with _org (for normal state), _over (first rollover state), and _over2 (for the secondary rollover state). I guess my issue lies now in targeting the circle buttons for the disjointed rollover, or secondary rollover. Please see the mockup link.
The following mockup is exactly what I need for navigation. Click here for mockup
UPDATE: 06.30.10 Working now!!! I can't post more than one link though...argh! I'll post a comment with the test link.
I'm very curious as to how I could use an array and loop to simplify this, but I don't want to be a bother. I'm also confused as to why the code above never worked. It seemed I was selecting the right elements, but the src never changed. I'm certain I was doing something wrong, but I'm here to learn. :)
$(document).ready(function(){
//Rollovers for circle buttons
$(".circleBtn").hover(
function(){
this.src = this.src.replace("_org","_over");
},
function(){
this.src = this.src.replace("_over","_org");
});
//Rollovers for navigation buttons
$(".navBtn").hover(
function(){
this.src = this.src.replace("_org","_over");
},
function(){
this.src = this.src.replace("_over","_org");
});
//Disjointed rollovers - use secondary rollover for circle imgs
$(".genBtn80").hover(
function(){
this.src = this.src.replace("_org","_over");
$("#janice_circle").attr("src", "images/janice_over2.gif");
$("#sugi_circle").attr("src", "images/sugi_over2.gif");
},
function(){
this.src = this.src.replace("_over","_org");
$("#janice_circle").attr("src", "images/janice_org.gif");
$("#sugi_circle").attr("src", "images/sugi_org.gif");
});
$(".genBtn70").hover(
function(){
this.src = this.src.replace("_org","_over");
$("#hatsuko_circle").attr("src", "images/hatsuko_over2.gif");
$("#satoko_circle").attr("src", "images/satoko_over2.gif");
},
function(){
this.src = this.src.replace("_over","_org");
$("#hatsuko_circle").attr("src", "images/hatsuko_org.gif");
$("#satoko_circle").attr("src", "images/satoko_org.gif");
});
$(".genBtn60").hover(
function(){
this.src = this.src.replace("_org","_over");
$("#noriko_circle").attr("src", "images/noriko_over2.gif");
$("#yuki_circle").attr("src", "images/yuki_over2.gif");
},
function(){
this.src = this.src.replace("_over","_org");
$("#noriko_circle").attr("src", "images/noriko_org.gif");
$("#yuki_circle").attr("src", "images/yuki_org.gif");
});
$(".genBtn50").hover(
function(){
this.src = this.src.replace("_org","_over");
$("#ritsuko_circle").attr("src", "images/ritsuko_over2.gif");
$("#yuka_circle").attr("src", "images/yuka_over2.gif");
},
function(){
this.src = this.src.replace("_over","_org");
$("#ritsuko_circle").attr("src", "images/ritsuko_org.gif");
$("#yuka_circle").attr("src", "images/yuka_org.gif");
});
$(".genBtn40").hover(
function(){
this.src = this.src.replace("_org","_over");
$("#christina_circle").attr("src", "images/christina_over2.gif");
$("#chiharu_circle").attr("src", "images/chiharu_over2.gif");
},
function(){
this.src = this.src.replace("_over","_org");
$("#christina_circle").attr("src", "images/christina_org.gif");
$("#chiharu_circle").attr("src", "images/chiharu_org.gif");
});
$(".genBtn30").hover(
function(){
this.src = this.src.replace("_org","_over");
$("#haruko_circle").attr("src", "images/haruko_over2.gif");
$("#shiho_circle").attr("src", "images/shiho_over2.gif");
},
function(){
this.src = this.src.replace("_over","_org");
$("#haruko_circle").attr("src", "images/haruko_org.gif");
$("#shiho_circle").attr("src", "images/shiho_org.gif");
});
$(".genBtn20").hover(
function(){
this.src = this.src.replace("_org","_over");
$("#aoi_circle").attr("src", "images/aoi_over2.gif");
$("#tomoko_circle").attr("src", "images/tomoko_over2.gif");
$("#miho_circle").attr("src", "images/miho_over2.gif");
},
function(){
this.src = this.src.replace("_over","_org");
$("#aoi_circle").attr("src", "images/aoi_org.gif");
$("#tomoko_circle").attr("src", "images/tomoko_org.gif");
$("#miho_circle").attr("src", "images/miho_org.gif");
});
});
My first approach would be to assign the circles to empty css classes just to group them and select them with jquery. For example, circles 1, 4 and 5 could have the class "nav1_links". Remember that you can assign multiple classes to an element, which is great if you want to have one link be under the umbrellas of two nav links, e.g. nav 1 highlights 1, 4 and 5 and nav 2 highlights 1, 2 and 3 -- so circle 1 would have the attribute class="nav1_links nav2_links"
. Then you could use jquery to access the appropriate circles:
$("#nav1").hover(function(){
this.src = this.src.replace("_org","_over"); // Change src for nav1
$(".nav1_links").attr("src", "rolloverState.png"); // Change src for all corresponding circles
});
If the image for each circle is different, however, this gets a bit more tricky. The easiest way to handle this (though not the cleanest) would be to just repeat that line for each circle involved, but replace the class name ".nav1_links" with the id name of the individual circle ("#circleID").
The more flexible (and complex) way would be to put all possible src values for one circle into an array, then use .each() to iterate through all the relevant circles for the currently active nav link and apply the appropriate src from the array of srcs for each circle. But arrays and for loops are a whole separate question, so if that doesn't make sense, then just stick with the easy route for now (I'm not sure how much scripting experience you have).
Does that answer your question? I admit I'm a bit confused about your notion of disjointed/secondary rollovers.
There's no simple answer to such a huge question. What you're asking is "how do I make this web page?"
I think that question you looked at earlier sets you on the right track. Your best bet is to use the .css() or .addClass() and .removeClass() methods. For example, if your first nav button has id="nav1" and you want it to highlight buttons 1, 4, and 5, the first thing you would do is:
$("#nav1").mouseover(function(){
$("#button1").addClass("circleHighlight");
$("#button4").addClass("circleHighlight");
$("#button5").addClass("circleHighlight");
});
$("#nav1").mouseout(function(){
$("#button1").removeClass("circleHighlight");
$("#button1").removeClass("circleHighlight");
$("#button1").removeClass("circleHighlight");
});
Then in your css, define what you want .circleHighlight to look like. If you want to change the href for each of those circles (to put in links and text, etc.) dynamically, you could add a line like this to that first function:
$("#button1").attr('href', 'http://www.address.com');
Also, if you want to clean things up a bit, you could create an array for each nav button on the bottom that holds which circles that button should access. Then you could also create an array of the nav buttons. That way, you could use a for loop (or .each() in jquery) to make those changes to all of the nav buttons, and in turn all of the circles that each individual nav button should affect.
Does that help at all? If you need more specific help, you might want to ask a specific question. Or just try things out and mess with the jquery until it works -- that's how i've been learning.enter code here
精彩评论