M
markszlazak
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:lightgreen;
text-align:center
}
.calendarRow {
height:30;
}
</style>
</head>
<body>
<table id='calendar' border='1' width='700' cellpadding='0'
cellspacing='0'>
<tr>
<td class="calendarHeader">Jennie</td>
<td class="calendarHeader">Mark</td>
</tr>
<tr class='calendarRow'>
<td id='1|Jennie'></td>
<td id='1|Mark'></td>
</tr>
<tr class='calendarRow'>
<td id='2|Jennie'></td>
<td id='2|Mark'></td>
</tr>
<tr class='calendarRow'>
<td id='3|Jennie'></td>
<td id='3|Mark'></td>
</tr>
<tr class='calendarRow'>
<td id='4|Jennie'></td>
<td id='4|Mark'></td>
</tr>
<tr class='calendarRow'>
<td id='5|Jennie'></td>
<td id='5|Mark'></td>
</tr>
<tr class='calendarRow'>
<td id='6|Jennie'></td>
<td id='6|Mark'></td>
</tr>
<tr class='calendarRow'>
<td id='7|Jennie'></td>
<td id='7|Mark'></td>
</tr>
</table>
<script>
var calendar = document.getElementById('calendar'),
slots = calendar.getElementsByTagName('td'),
slot;
function addDIVs(slot) {
var div = document.createElement('div');
div.style.position = 'relative';
div.style.backgroundColor = 'transparent';
div.style.visibility = 'visible';
div.style.top = 0;
div.style.left = 2;
div.style.height = 24;
div.style.width = 342;
slot.appendChild(div);
var outerDIV = div;
div = document.createElement('div');
div.style.position = 'absolute';
div.style.backgroundColor = 'lightyellow';
div.style.visibility = 'hidden';
div.style.top = 0;
div.style.left = 0;
div.style.height = 24;
div.style.width = 342;
outerDIV.appendChild(div);
div = document.createElement('div');
div.style.position = 'absolute';
div.style.top = 0;
div.style.left = 0;
div.style.height = 24;
div.style.width = 342;
div.style.backgroundColor = 'transparent';
div.style.visibility = 'visible';
outerDIV.appendChild(div);
}
function mouseoutHandlerDIV(e) {
var el = getEventTarget(e);
if (el.nextSibling) {
el.style.visibility = "hidden";
el.nextSibling.style.visibility = "visible";
}
}
function mouseoverHandlerDIV(e) {
var el = getEventTarget(e);
el.style.visibility = 'hidden';
el.previousSibling.style.visibility = 'visible';
}
function addEvent(el, evtType, listener, captures) {
if (el.addEventListener) {
el.addEventListener(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.srcElement) { return
window.event.srcElement; }
if (e && e.target) { return e.target; }
return null;
}
for (var i=0; i < slots.length; i++) {
if (slots.id.length > 0) {
addDIVs(slots);
slot = slots.firstChild;
addEvent(slot.firstChild, 'mouseout', mouseoutHandlerDIV, false);
addEvent(slot.lastChild, 'mouseover', mouseoverHandlerDIV, 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:lightgreen;
text-align:center
}
.calendarRow {
height:30;
}
</style>
</head>
<body>
<table id='calendar' border='1' width='700' cellpadding='0'
cellspacing='0'>
<tr>
<td class="calendarHeader">Jennie</td>
<td class="calendarHeader">Mark</td>
</tr>
<tr class='calendarRow'>
<td id='1|Jennie'></td>
<td id='1|Mark'></td>
</tr>
<tr class='calendarRow'>
<td id='2|Jennie'></td>
<td id='2|Mark'></td>
</tr>
<tr class='calendarRow'>
<td id='3|Jennie'></td>
<td id='3|Mark'></td>
</tr>
<tr class='calendarRow'>
<td id='4|Jennie'></td>
<td id='4|Mark'></td>
</tr>
<tr class='calendarRow'>
<td id='5|Jennie'></td>
<td id='5|Mark'></td>
</tr>
<tr class='calendarRow'>
<td id='6|Jennie'></td>
<td id='6|Mark'></td>
</tr>
<tr class='calendarRow'>
<td id='7|Jennie'></td>
<td id='7|Mark'></td>
</tr>
</table>
<script>
var calendar = document.getElementById('calendar'),
slots = calendar.getElementsByTagName('td'),
slot;
function addDIVs(slot) {
var div = document.createElement('div');
div.style.position = 'relative';
div.style.backgroundColor = 'transparent';
div.style.visibility = 'visible';
div.style.top = 0;
div.style.left = 2;
div.style.height = 24;
div.style.width = 342;
slot.appendChild(div);
var outerDIV = div;
div = document.createElement('div');
div.style.position = 'absolute';
div.style.backgroundColor = 'lightyellow';
div.style.visibility = 'hidden';
div.style.top = 0;
div.style.left = 0;
div.style.height = 24;
div.style.width = 342;
outerDIV.appendChild(div);
div = document.createElement('div');
div.style.position = 'absolute';
div.style.top = 0;
div.style.left = 0;
div.style.height = 24;
div.style.width = 342;
div.style.backgroundColor = 'transparent';
div.style.visibility = 'visible';
outerDIV.appendChild(div);
}
function mouseoutHandlerDIV(e) {
var el = getEventTarget(e);
if (el.nextSibling) {
el.style.visibility = "hidden";
el.nextSibling.style.visibility = "visible";
}
}
function mouseoverHandlerDIV(e) {
var el = getEventTarget(e);
el.style.visibility = 'hidden';
el.previousSibling.style.visibility = 'visible';
}
function addEvent(el, evtType, listener, captures) {
if (el.addEventListener) {
el.addEventListener(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.srcElement) { return
window.event.srcElement; }
if (e && e.target) { return e.target; }
return null;
}
for (var i=0; i < slots.length; i++) {
if (slots.id.length > 0) {
addDIVs(slots);
slot = slots.firstChild;
addEvent(slot.firstChild, 'mouseout', mouseoutHandlerDIV, false);
addEvent(slot.lastChild, 'mouseover', mouseoverHandlerDIV, false);
}
}
</script>
</body>
</html>