Nick Robins wrote:
RobG wrote:
Regardless, until a solution is proposed for the flicker problem
caused by the mouseover/out, it's not going to be useful. I
think Richard has a good idea - have the mouseover change an
adjoining cell.
That was the main reason I suggested using the style property, the
status of the pointer hasn't changed, there's no new element to alter
things thus the flicker is avoided.
Your method neatly avoids flicker, but so does hiding/showing
the elements without using CSS. Your CSS method is much more
reliable in Firefox however, as discussed below.
An artifact of mouseover/out in Firefox is that the events don't
always fire - rapid mouse movement can prevent them from
happening - however the CSS method does not display this.
Below is a test page that has two cells: the left one just
toggles the display of an image or text, the right hides the
text and uses CSS background image to display the image. Both
avoid flicker.
In the left cell, rapid mouse movement can cause the mouseout
event not to fire. The far right cell keeps a log of the last 10
events, the element that fired them and the cell the event is
registered to so it is easy to see a mouseover on the left cell
immediately followed by a mouseover on the right. The missing
mouseout means the image is still displayed in the left cell.
It also neatly shows the bubbling of events - sometimes the
mouseover is called by an image or span and not the td.
Internally, mouseout/over is being called constantly in the left
cell (it happens in the right cell too if something is
displayed).
Interestingly, in IE both cells behave completely reliably - if
mouseover fires, then mouseout is guaranteed (at least as far as
my testing can determine). Is this a bug with Firefox
mouseover/out events?
Comment?
<style type="text/css">
/* set the td size to stop the td collapsing
when content is hidden */
td { width: 150px; height: 100px; }
</style>
<script type="text/javascript">
var msgTxt = ['<br>','<br>','<br>','<br>','<br>',
'<br>','<br>','<br>','<br>','<br>'];
var evtCnt = 0;
function writeMsg(a,b,c){
var msgCel = document.getElementById('msgCel');
var col = 'red';
col = (c == 'left')? 'red' : 'green';
msgTxt.unshift(a + ' ' + b + ' '
+ '<span style="color: ' + col
+ '; font-weight: bold">' + c + '</span>'
+ ' ' + evtCnt + '<br>');
msgTxt.pop();
msgCel.innerHTML = msgTxt.join('');
evtCnt++;
}
function addImage(tableCell,evt) {
tableCell.style.backgroundImage = "url(1.gif)";
tableCell.firstChild.style.display = "none";
var e = evt || window.event;
var c = e.target || e.srcElement;
writeMsg(e.type,c.nodeName,tableCell.id);
}
function delImage(tableCell,evt) {
tableCell.style.backgroundImage = "";
tableCell.firstChild.style.display = "";
var e = evt || window.event;
var c = e.target || e.srcElement;
writeMsg(e.type,c.nodeName,tableCell.id);
}
function addImage1(tableCell,evt) {
tableCell.childNodes[0].style.display = "";
tableCell.childNodes[1].style.display = "none";
var e = evt || window.event;
var c = e.target || e.srcElement;
writeMsg(e.type,c.nodeName,tableCell.id);
}
function delImage1(tableCell,evt) {
tableCell.childNodes[0].style.display = "none";
tableCell.childNodes[1].style.display = "";
var e = evt || window.event;
var c = e.target || e.srcElement;
writeMsg(e.type,c.nodeName,tableCell.id);
}
</script>
<table border="1">
<tr>
<td id="left" onmouseover="addImage1(this,event)"
onmouseout="delImage1(this,event)"><img
src="1.gif" style="display: none"><span>some text</span>
</td>
<td id="right" onmouseover="addImage(this,event)"
onmouseout="delImage(this,event)"><span>some text</span>
</td>
<td style="width: 200px" id="msgCel">
<br><br><br><br><br><br><br><br><br><br>
</td>
</tr>
</table>
--
Rob