alpine Posted September 11, 2006 Share Posted September 11, 2006 Can anyone look at this javascript and maybe point out why it is so slow in Internet Explorer ? (IE6)In Firefox it is all ok and very responsive, while in IE its really slow and not following the mouse as i move it over the rows.[color=blue]var oppr_tbody_bgcolor;function set_tbodybg(obj,col) {oppr_tbody_bgcolor=obj.style.backgroundColor;obj.style.backgroundColor=col;}function reset_tbodybg(obj) {obj.style.backgroundColor=oppr_tbody_bgcolor;}[/color]Called like this:[color=blue]<tbody id="tbody_$unique" style="background-color: $bgfarve;" onmouseout="reset_tbodybg(this);" onmouseover="set_tbodybg(this,'#dddddd');"><tr><td blah..>ksgdk</td></tr></tbody>[/color]I have another function setting the tr bgcolor something if something is done and want that color to be always on top if set, thats why i use the set/reset on tbody as this has lower priority and will be surpressed. Quote Link to comment Share on other sites More sharing options...
alpine Posted September 12, 2006 Author Share Posted September 12, 2006 OK - i found out that it must be the tbody properties IE cant handle, and it get worse the more rows and tbody tags i have.So i headed on another angle to switch bgcolor as IE handles TR much much faster.Now my problem is that it works in IE (and Opera) but not in Firefox.The following script sets onmouseover and onmouseout style bgcolor IF the current colour is not one particular.But Firefox ignores the if condition:[color=blue]<tr id="tr_$unique_id" style="background-color: $bgcolor;" onmouseout="javascript: if(this.style.backgroundColor!='#ccff66')this.style.backgroundColor='$bgfarve';" onmouseover="javascript: if(this.style.backgroundColor!='#ccff66')this.style.backgroundColor='#dddddd';" onclick="blah..">[/color]Any ideas ? Quote Link to comment Share on other sites More sharing options...
alpine Posted September 13, 2006 Author Share Posted September 13, 2006 [color=red]if(this.style.backgroundColor!='#ccff66')[/color] works in IE and Opera but not in Firefoxwhile[color=red]if(this.style.backgroundColor!='rgb(204, 255, 102)')[/color] works in Firefox but not in IE or OperaI normally try to use things that works in all those browsers, and hate to be dependable of browserdetection scripts - but this time i really don't know...... not anyone out there that can give any answers or come up with other ideas ?? Quote Link to comment Share on other sites More sharing options...
fenway Posted September 20, 2006 Share Posted September 20, 2006 Just write/find a quick 3-line function to convert RGB to HEX. Quote Link to comment Share on other sites More sharing options...
obsidian Posted September 20, 2006 Share Posted September 20, 2006 also, i would recommend doing something like this instead of assigning the onmouseover and onmouseout to every one of your table rows:[code]<script type="text/javascript">window.onload = function() { x = document.getElementsByTagName('TR'); for (i = 0; i < x.length; i++) { x[i].onmouseover = function() { this.className = 'color2'; } x[i].onmouseout = function() { this.className = 'color1'; } }}</script>[/code]also, by changing className instead of backgroundColor directly, you can assign the colors in your CSS, and they will be interpreted correctly across all browsers.hope this helps. Quote Link to comment Share on other sites More sharing options...
fenway Posted September 21, 2006 Share Posted September 21, 2006 Personally, I prefer not to "hide" event handler assignments, but you should definitely have functions for these regardless. Quote Link to comment Share on other sites More sharing options...
obsidian Posted September 21, 2006 Share Posted September 21, 2006 [quote author=fenway link=topic=107621.msg438418#msg438418 date=1158799498]Personally, I prefer not to "hide" event handler assignments, but you should definitely have functions for these regardless.[/quote]to me, it depends on how widespread they are on the page. i hate to see every table cell in a page with an onmouseover and onmouseout event handler. however, if there are single instances throughout the page, i would definitely create them inline. it may just be a preference thing, though. i tend to be a stickler for neat markup. Quote Link to comment Share on other sites More sharing options...
fenway Posted September 21, 2006 Share Posted September 21, 2006 I too don't like messy or bulky code... but I hate not knowing when event handlers are firing, and then having to find them. Of course, if you're writing out lots of TR/TDs anyway, if should be handled server-side, in which case it's only in one place anyway ;-) Quote Link to comment Share on other sites More sharing options...
obsidian Posted September 21, 2006 Share Posted September 21, 2006 [quote author=fenway link=topic=107621.msg438432#msg438432 date=1158799951]Of course, if you're writing out lots of TR/TDs anyway, if should be handled server-side, in which case it's only in one place anyway ;-)[/quote]hehe... very good point. you got me there. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.