Spudhead
04-18-2008, 01:48 PM
Evidently I'm failing to grasp something... I'm trying to grab all the <div> elements below, add an opacity effect to the images in them, and add mouseover handlers to the enclosing hrefs to turn the opacity on and off.
But the code below has the effect that mousing over ANY of the hrefs toggles the opacity effect on just the bottom image.
Event.observe(window, 'load', function() {
$$("div.insetcontent").each(function(oBox){
oLink = oBox.childElements()[0];
oLinkImg = oLink.childElements()[0];
new Effect.Opacity(oLinkImg, {duration:0, from:1.0, to:0.5});
Event.observe(oLink, 'mouseover', function() {new Effect.Opacity(oLinkImg, {duration:0, from:0.5, to:1.0})});
Event.observe(oLink, 'mouseout', function() {new Effect.Opacity(oLinkImg, {duration:0, from:1.0, to:0.5})});
});
});
<div class="insetcontent" id="b1"><a id="l1" href="/about/simon.html" title="Read more"><img id="i1" src="/img/snippets/pc5.jpg" width="107" height="57" alt="Simons experience is focussed on portfolio and asset management" /><p>Simons experience is focussed on portfolio and asset management</p></a></div>
<div class="insetcontent" id="b2"><a id="l2" href="/about/simon.html" title="Read more"><img id="i2" src="/img/snippets/pc5.jpg" width="107" height="57" alt="Simons experience is focussed on portfolio and asset management" /><p>Simons experience is focussed on portfolio and asset management</p></a></div>
<div class="insetcontent" id="b3"><a id="l3" href="/about/simon.html" title="Read more"><img id="i3" src="/img/snippets/pc5.jpg" width="107" height="57" alt="Simons experience is focussed on portfolio and asset management" /><p>Simons experience is focussed on portfolio and asset management</p></a></div>
<div class="insetcontent" id="b4"><a id="l4" href="/about/simon.html" title="Read more"><img id="i4" src="/img/snippets/pc5.jpg" width="107" height="57" alt="Simons experience is focussed on portfolio and asset management" /><p>Simons experience is focussed on portfolio and asset management</p></a></div>
But the code below has the effect that mousing over ANY of the hrefs toggles the opacity effect on just the bottom image.
Event.observe(window, 'load', function() {
$$("div.insetcontent").each(function(oBox){
oLink = oBox.childElements()[0];
oLinkImg = oLink.childElements()[0];
new Effect.Opacity(oLinkImg, {duration:0, from:1.0, to:0.5});
Event.observe(oLink, 'mouseover', function() {new Effect.Opacity(oLinkImg, {duration:0, from:0.5, to:1.0})});
Event.observe(oLink, 'mouseout', function() {new Effect.Opacity(oLinkImg, {duration:0, from:1.0, to:0.5})});
});
});
<div class="insetcontent" id="b1"><a id="l1" href="/about/simon.html" title="Read more"><img id="i1" src="/img/snippets/pc5.jpg" width="107" height="57" alt="Simons experience is focussed on portfolio and asset management" /><p>Simons experience is focussed on portfolio and asset management</p></a></div>
<div class="insetcontent" id="b2"><a id="l2" href="/about/simon.html" title="Read more"><img id="i2" src="/img/snippets/pc5.jpg" width="107" height="57" alt="Simons experience is focussed on portfolio and asset management" /><p>Simons experience is focussed on portfolio and asset management</p></a></div>
<div class="insetcontent" id="b3"><a id="l3" href="/about/simon.html" title="Read more"><img id="i3" src="/img/snippets/pc5.jpg" width="107" height="57" alt="Simons experience is focussed on portfolio and asset management" /><p>Simons experience is focussed on portfolio and asset management</p></a></div>
<div class="insetcontent" id="b4"><a id="l4" href="/about/simon.html" title="Read more"><img id="i4" src="/img/snippets/pc5.jpg" width="107" height="57" alt="Simons experience is focussed on portfolio and asset management" /><p>Simons experience is focussed on portfolio and asset management</p></a></div>