So at work today, I wanted to see if I could create a lame mouse over effect to let feel like they were highlighting a listing. I wanted to pop out the moused over listing on the page by putting a thin border around the moused over div and then change the background. I was able to create the effect with javascript and coldfusion very easily. Because I don’t host this site on a coldfusion server, I will just show the javascript with some rendered HTML.
To save some time, I will explain the javascript and how to call it. You can grab the css from the example page.
<script type="text/javascript">
//<![CDATA[
var listing = {
g:function(id) {
return document.getElementById(id);
},
// function to change the background and border of listing on mouse over
highlight:function(id) {
listing_el = listing.g("listing" + id);
if(id != 1) { //this is what to do for all divs other then first one
id_above = id - 1;
listing_above_el = listing.g("listing" + id_above);
listing_above_el.style.border = "#fff 2px solid"; //removes border on result above highlighted
listing_el.style.backgroundColor = "#fffae7";
listing_el.style.border = "#837b97";
}
else {
listing_el.className = "highlight_el";
listing_el.style.backgroundColor = "#fffae7";
listing_el.style.border = "#837b97";
}
},
normal:function(id) {
listing_el = listing.g("listing" + id);
if(id != 1) {
id_above = id - 1;
listing_above_el = listing.g("listing" + id_above);
listing_above_el.style.borderBottom = "#cccccc 2px dotted"; //restores border to result above highlighted
listing_el.style.backgroundColor = "#ffffff";
listing_el.style.border = "#ffffff 2px solid";
listing_el.style.borderBottom = "#cccccc 2px dotted";
}
else {
listing_el.className = "normal_el";
listing_el.style.backgroundColor = "#ffffff";
listing_el.style.border = "#ffffff 2px solid";
listing_el.style.borderBottom = "#cccccc 2px dotted";
}
}
//]]>
</script>
The HTML can be spit through some query or loop and is straight forward.
This can be completed repeated and by dynamically changing the value i you can populate the results so that You can see the finished product here.
<div id="listing1" class="listing" onmouseover="listing.highlight('1');" onmouseout="listing.normal('1');">
<div id="listing_top">
<span class="left">
<a href="javascript:void(0);" title="121 Initech Rd">121 Initech Rd</a>
</span>
</div>
<div id="listing_left">
<a href="javascript:void(0);" title="121 Initech Rd"><img src="images/inventory/thumbs/0/0/0/000976.jpg" alt="121 Initech Rd" class="displayed" width="151" /></a>
2.00 bed 3.00 bath 1296 sqft<br />
Lake Home<br />
Listing: 08-1979
</div>
<div id="listing_right"><span class="large_price">$198699</span> One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. He lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightly domed and divided by arches into stiff sections. The bedding was hardly able to cover it and seemed ready to slide off any moment. His many legs, pitifully thin compared with the size of the rest of him, waved about helplessly as he looked. "What's happened to me? " he thought. It wasn't a dream.</div>
<div class="clear"></div>
</div></code></code>
<code><div id="listing2" class="listing" onmouseover="listing.highlight('2');" onmouseout="listing.normal('2');">
<div id="listing_top">
<span class="left">
<a href="javascript:void(0);" title="121 Initech Rd">121 Initech Rd</a>
</span>
</div>
<div id="listing_left">
<a href="javascript:void(0);" title="121 Initech Rd"><img src="images/inventory/thumbs/0/0/0/000976.jpg" alt="121 Initech Rd" class="displayed" width="151" /></a>
2.00 bed 3.00 bath 1296 sqft<br />
Lake Home<br />
Listing: 08-1979
</div>
<div id="listing_right"><span class="large_price">$198699</span> His room, a proper human room although a little too small, lay peacefully between its four familiar walls. A collection of textile samples lay spread out on the table - Samsa was a travelling salesman - and above it there hung a picture that he had recently cut out of an illustrated magazine and housed in a nice, gilded frame. It showed a lady fitted out with a fur hat and fur boa who sat upright, raising a heavy fur muff that covered the whole of her lower arm towards the viewer.</div>
<div class="clear"></div>
</div>
[sourcecode language='html']
<div id="listingi" class="listing" onmouseover="listing.highlight('i');" onmouseout="listing.normal('i');">
