Speed up onmouseover of rows and cols

J

johkar

This code from siteexperts.com tends to be slow onmouseover if you get
more than a 50 rows. Suggestions for increasing speed?

http://www.siteexperts.com/tips/styles/ts25/page1.asp

Thanks, John

var rowHighlight = true // turn on row highlights
var colHighlight = true // turn off row highlights

function getElement(el) {
var tagList = new Object
for (var i = 1; i < arguments.length; i++)
tagList[arguments] = true
while ((el!=null) && (tagList[el.tagName]==null))
el = el.parentElement
return el
}

function checkHighlight(which) {
var el = getElement(event.srcElement,"TH","TD")
if (el==null) return
if ((el.tagName=="TH") && (colHighlight)) {
var idx = el.cellIndex
var table = getElement(el, "TABLE")
var column = table.all.tags("COL")[idx]
if (which)
column.className="cover"
else
column.className=""
}
if ((el.tagName=="TD") && (rowHighlight)) {
var row = getElement(el, "TR")
var table = getElement(row, "TABLE")
if (which)
row.className = "rover"
else
row.className = ""
cache = row
}
}
 
Y

Yann-Erwan Perio

johkar said:
This code from siteexperts.com tends to be slow onmouseover if you get
more than a 50 rows. Suggestions for increasing speed?

http://www.siteexperts.com/tips/styles/ts25/page1.asp
if (which)
column.className="cover"
else
column.className=""

Setting the className property is much more expensive than setting a
simple style property! Try switching to style updates instead of
className updates.

Also, passing the 'this' value to the functions, and minimizing node
lookups, could be a good idea. On a different level, rewriting the
script and using caching systems may be interesting (removing mouseout
handler).


HTH,
Yep.
 
T

Thomas 'PointedEars' Lahn

Yann-Erwan Perio said:
Setting the className property is much more expensive than setting a
simple style property!

Why should it?


PointedEars
 
T

Thomas 'PointedEars' Lahn

Jim said:
because the CSS cascade needs to be re-computed.

As it would be if the "style" property/attribute changes.
That property/attribute is not off the cascade.


PointedEars
 
J

Jim Ley

As it would be if the "style" property/attribute changes.
That property/attribute is not off the cascade.

Except of course setting a single property on a style doesn't need to
compute as much of the cascade (inline style can only influence direct
descendants, class can of course do much more.)

Jim.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top