Could someone check out the following code and please help me
understand the problem and fix it. It seems like some events are not
firing when my mouse moves over the table cells to quickly causing
some table cells to stay yellow when you move out of them instead of
going back to blue.
(Note that I'm using DIV's inside this table because the lightyellow
one will contain an image that will be mousedowned on to start a cell
selection mode which table cells can be selected or deselected quickly
in a column by a drag-N-drop-type procedure). Here is the code.
<html>
<head>
<title></title>
<style>
#calendar {
background-color:lightblue ;
}
.calendarHeader {
background-color:lightgree n;
text-align:center
}
.calendarRow {
height:30;
}
</style>
</head>
<body>
<table id='calendar' border='1' width='700' cellpadding='0'
cellspacing='0' >
<tr>
<td class="calendar Header">Jennie</td>
<td class="calendar Header">Mark</td>
</tr>
<tr class='calendar Row'>
<td id='1|Jennie'></td>
<td id='1|Mark'></td>
</tr>
<tr class='calendar Row'>
<td id='2|Jennie'></td>
<td id='2|Mark'></td>
</tr>
<tr class='calendar Row'>
<td id='3|Jennie'></td>
<td id='3|Mark'></td>
</tr>
<tr class='calendar Row'>
<td id='4|Jennie'></td>
<td id='4|Mark'></td>
</tr>
<tr class='calendar Row'>
<td id='5|Jennie'></td>
<td id='5|Mark'></td>
</tr>
<tr class='calendar Row'>
<td id='6|Jennie'></td>
<td id='6|Mark'></td>
</tr>
<tr class='calendar Row'>
<td id='7|Jennie'></td>
<td id='7|Mark'></td>
</tr>
</table>
<script>
var calendar = document.getEle mentById('calen dar'),
slots = calendar.getEle mentsByTagName( 'td'),
slot;
function addDIVs(slot) {
var div = document.create Element('div');
div.style.posit ion = 'relative';
div.style.backg roundColor = 'transparent';
div.style.visib ility = 'visible';
div.style.top = 0;
div.style.left = 2;
div.style.heigh t = 24;
div.style.width = 342;
slot.appendChil d(div);
var outerDIV = div;
div = document.create Element('div');
div.style.posit ion = 'absolute';
div.style.backg roundColor = 'lightyellow';
div.style.visib ility = 'hidden';
div.style.top = 0;
div.style.left = 0;
div.style.heigh t = 24;
div.style.width = 342;
outerDIV.append Child(div);
div = document.create Element('div');
div.style.posit ion = 'absolute';
div.style.top = 0;
div.style.left = 0;
div.style.heigh t = 24;
div.style.width = 342;
div.style.backg roundColor = 'transparent';
div.style.visib ility = 'visible';
outerDIV.append Child(div);
}
function mouseoutHandler DIV(e) {
var el = getEventTarget( e);
if (el.nextSibling ) {
el.style.visibi lity = "hidden";
el.nextSibling. style.visibilit y = "visible";
}
}
function mouseoverHandle rDIV(e) {
var el = getEventTarget( e);
el.style.visibi lity = 'hidden';
el.previousSibl ing.style.visib ility = 'visible';
}
function addEvent(el, evtType, listener, captures) {
if (el.addEventLis tener) {
el.addEventList ener(evtType, listener, captures);
return true;
}
else if (el.attachEvent ) {
return el.attachEvent( 'on' + evtType, listener);
}
else {
el['on' + evtType] = listener;
}
}
function getEventTarget( e) {
if (window.event && window.event.sr cElement) { return
window.event.sr cElement; }
if (e && e.target) { return e.target; }
return null;
}
for (var i=0; i < slots.length; i++) {
if (slots[i].id.length 0) {
addDIVs(slots[i]);
slot = slots[i].firstChild;
addEvent(slot.f irstChild, 'mouseout', mouseoutHandler DIV, false);
addEvent(slot.l astChild, 'mouseover', mouseoverHandle rDIV, false);
}
}
</script>
</body>
</html>
understand the problem and fix it. It seems like some events are not
firing when my mouse moves over the table cells to quickly causing
some table cells to stay yellow when you move out of them instead of
going back to blue.
(Note that I'm using DIV's inside this table because the lightyellow
one will contain an image that will be mousedowned on to start a cell
selection mode which table cells can be selected or deselected quickly
in a column by a drag-N-drop-type procedure). Here is the code.
<html>
<head>
<title></title>
<style>
#calendar {
background-color:lightblue ;
}
.calendarHeader {
background-color:lightgree n;
text-align:center
}
.calendarRow {
height:30;
}
</style>
</head>
<body>
<table id='calendar' border='1' width='700' cellpadding='0'
cellspacing='0' >
<tr>
<td class="calendar Header">Jennie</td>
<td class="calendar Header">Mark</td>
</tr>
<tr class='calendar Row'>
<td id='1|Jennie'></td>
<td id='1|Mark'></td>
</tr>
<tr class='calendar Row'>
<td id='2|Jennie'></td>
<td id='2|Mark'></td>
</tr>
<tr class='calendar Row'>
<td id='3|Jennie'></td>
<td id='3|Mark'></td>
</tr>
<tr class='calendar Row'>
<td id='4|Jennie'></td>
<td id='4|Mark'></td>
</tr>
<tr class='calendar Row'>
<td id='5|Jennie'></td>
<td id='5|Mark'></td>
</tr>
<tr class='calendar Row'>
<td id='6|Jennie'></td>
<td id='6|Mark'></td>
</tr>
<tr class='calendar Row'>
<td id='7|Jennie'></td>
<td id='7|Mark'></td>
</tr>
</table>
<script>
var calendar = document.getEle mentById('calen dar'),
slots = calendar.getEle mentsByTagName( 'td'),
slot;
function addDIVs(slot) {
var div = document.create Element('div');
div.style.posit ion = 'relative';
div.style.backg roundColor = 'transparent';
div.style.visib ility = 'visible';
div.style.top = 0;
div.style.left = 2;
div.style.heigh t = 24;
div.style.width = 342;
slot.appendChil d(div);
var outerDIV = div;
div = document.create Element('div');
div.style.posit ion = 'absolute';
div.style.backg roundColor = 'lightyellow';
div.style.visib ility = 'hidden';
div.style.top = 0;
div.style.left = 0;
div.style.heigh t = 24;
div.style.width = 342;
outerDIV.append Child(div);
div = document.create Element('div');
div.style.posit ion = 'absolute';
div.style.top = 0;
div.style.left = 0;
div.style.heigh t = 24;
div.style.width = 342;
div.style.backg roundColor = 'transparent';
div.style.visib ility = 'visible';
outerDIV.append Child(div);
}
function mouseoutHandler DIV(e) {
var el = getEventTarget( e);
if (el.nextSibling ) {
el.style.visibi lity = "hidden";
el.nextSibling. style.visibilit y = "visible";
}
}
function mouseoverHandle rDIV(e) {
var el = getEventTarget( e);
el.style.visibi lity = 'hidden';
el.previousSibl ing.style.visib ility = 'visible';
}
function addEvent(el, evtType, listener, captures) {
if (el.addEventLis tener) {
el.addEventList ener(evtType, listener, captures);
return true;
}
else if (el.attachEvent ) {
return el.attachEvent( 'on' + evtType, listener);
}
else {
el['on' + evtType] = listener;
}
}
function getEventTarget( e) {
if (window.event && window.event.sr cElement) { return
window.event.sr cElement; }
if (e && e.target) { return e.target; }
return null;
}
for (var i=0; i < slots.length; i++) {
if (slots[i].id.length 0) {
addDIVs(slots[i]);
slot = slots[i].firstChild;
addEvent(slot.f irstChild, 'mouseout', mouseoutHandler DIV, false);
addEvent(slot.l astChild, 'mouseover', mouseoverHandle rDIV, false);
}
}
</script>
</body>
</html>
Comment