List Info

Thread: behavior.js and div swapping




behavior.js and div swapping
user name
2006-11-11 13:36:19
Hello,

I have just come across behavior.js and have a query
regarding its use
with a div swapping js script.

I have 7 images in divs on a page that each have a
corresponding hidden
div with text in it.
When mousing over / mousing out an image div, the relevant
hidden text
div shows.

eg - mousover #Fr1i1 and invisible #Fr1n1 shows.
mousover #Fr1i2 and invisible #Fr1n2 shows.
etc through to div 7.

This works fine using a div swapping js script with
onMouseOver="javascript:changeIt('Fr1n1','block');"
; and
onMouseOut="javascript:hideIt();"
etc in the <a> tags.

I understand its nicer to use less of this js specific code
in html and
love the idea of cleaning up the code but can't seem to work
out a nice
way about it - without creating one individual behaviour in
the CData
<head> bit for each div swapping.

var rules = {
    '.hover1' : {
        onmouseover : function() { hideIt();
changeIt('Fr1n1','block');
},
        onmouseout : function() { hideIt();
changeIt('Fr1n1','none'); }
    '.hover2' : {
        onmouseover : function() { hideIt();
changeIt('Fr1n2','block');
},
        onmouseout : function() { hideIt();
changeIt('Fr1n2','none'); }

etc

And if I have to create 7 behaviours in the head, this
doesn't seem to
make the code cleaner.

I'm using this on a portfolio page so 7 might grow into 30 -
in which
case creating a new rule for each folio item seems less than
appealing.

So my question is how can I do it better with a behaviour.js
style
approach.

Please help.

Thank you in advance.

p.s. I am not a javascript programmer so please talk in
layman's!!


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the
Google Groups "JavaScript Forum" group.
To post to this group, send email to
JavaScript-Informationgooglegroups.com
To unsubscribe from this group, send email to
JavaScript-Information-unsubscribegooglegroups.com
For more options, visit this group at http://groups-beta.google.com/group/JavaScript-I
nformation?hl=en
-~----------~----~----~----~------~----~------~--~---

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )