I went to the NYU Computer Lab in Room 210 at 48 Cooper Square today and blasted away for five hours straight at the "mouseover" flickering in assignment 5 but could never get it to go away cleanly in all situations. This was true even using Amos' "relatedTarget" approach in his email yesterday (Sunday!)
I puzzled over it on the subway home and at dinner. I came up with a new approach which I tried out tonight and which really works simply, cleanly and crisply. (Maybe we'll have Rice Krispies bars to celebrate at lunch this Saturday!) Unfortunately I'm now at the office using my grubby IE6 browser; the URL's for Mozilla Firefox are blocked on our computers. I'll be very busy the next few days at work but I'll try to get back to the lab soon to upload everything to onepotcooking. In any event, I have a vacation day on Friday when I can redo everything at NYU.
Meanwhile all the relevant code (html, css, js) is cut & pasted below. As for php, the nine thumbnails can be loaded via parameterized "includes", as we did in class on Saturday and which interested readers can already view under my id (johnpennisten) on onepotcooking.
The basic idea to stop the flickering is to have for each thumbnail one "outer" div which holds two "inner" divs, one for the thumbnail image and one for the thumbnail description. When the page first loads, the inner image div has "display: block" and the inner description div has "display: none". Event observers are set up on the OUTER thumbnail div for the mouseover and mouseout events. When you mouseover the OUTER thumbnail, the INNER image div is reset to display:none and the INNER description image is reset to display:block. When you mouseout, the reverse occurs. (display:inline can make things come up truncated.)
This way there is NEVER ANY REPOSTIONING OF ANYTHING; it's the repostioning that is likely the root cause of all this flickering business. Here is the code:
HTML ("tnail" is the outer div; "tnimg" and "tndat" are the inner divs):
div class="tnail" id="tn01"
div class="tnimg" id="tn01_img"
img title="image01" alt="thumbnail01" src="http://www.blogger.com/images/emandems.bmp" /div
div class="tndat" id="tn01_dat"
p strong use ems today! strong /p /div
/div
CSS:
".tnail { float: left; width: 125px; height: 90px; margin: 5px; padding: 0px; border: 0px;}"
".tnimg { display: block; background-color: aqua; width: 125px; height: 90px;}"
".tndat { display: none; background-color: white; width: 125px; height: 90px;}"
The ENTIRE javascript:
"// main event observer for window load"
"Event.observe(window, 'load', function() { setTnailMouseovers(); setTnailMouseouts(); });"
"// event observers for thumbnail mouseovers"
"function setTnailMouseovers() { var els = $$('.tnail'); els.each( function(el) { Event.observe(el, 'mouseover', function() { var tnimg = el.id + "_img"; var tndat = el.id + "_dat"; $(tnimg).setStyle({display:'none'}); $(tndat).setStyle({display:'block'}); }) })}"
"// event observers for thumbnail mouseouts"
"function setTnailMouseouts() { var els = $$('.tnail'); els.each( function(el) { Event.observe(el, 'mouseout', function() { var tnimg = el.id + "_img"; var tndat = el.id + "_dat"; $(tnimg).setStyle({display:'block'}); $(tndat).setStyle({display:'none'}); }) })}"