PDA

View Full Version : Drawing prior to screen presentation


tiggyboo
02-15-2003, 08:48 PM
I have some forms with fairly large chunks of javascript driving many of the menus. As I add complexity I'm beginning to notice delays in on-screen drawing. If given the choice, I'd prefer to have the entire display delayed up front as long as the form elements, etc. appeared instantaneously. In my old conventional programming days I used to create bitmaps off screen for this kind of thing - how can I achieve the same effect with javascript?
Thanks,
Tiggy

brothercake
02-16-2003, 04:32 AM
So - you draw all the menus hidden and use a show/hide function to make them work? And your page is getting slower because there's lots of them, and it's a lot of code to compile and render?


You ever used createElement()? Say yes or no, and we'll expand from there.

tiggyboo
02-17-2003, 12:52 AM
No, I never have used that function... please continue!
Thanks!

brothercake
02-24-2003, 04:21 PM
Well createElement allows you to create an element and add it to the flow of the page. So for eg:

var newDiv = document.createElement("div");
document.body.appendChild(newDiv);

Creates a div object called newDiv and appends it to the body element; you can equally append it to something else:

document.getElementById("some_thing").appendChild(newDiv);


Once it's there, you can manipulate it and add code to it. There are two core ways - setAttribute and innerHTML - innerHTML is not actually in the standards I don't think, it's an IE extension which others have adopted; setAttribute is in the standards but is not well supported in IE.

Anyway here's something you can get started with - this works in IE5/6, mozilla, opera 7, konqueror/safari:


<html><head></head><body>


<script>


function createIt() {

var newDiv = document.createElement("div");
document.body.appendChild(newDiv);

newDiv.setAttribute("style");
newDiv.style.position = "absolute";
newDiv.style.left = "20em";
newDiv.style.top = "10em";
newDiv.style.backgroundColor = "yellow";

newDiv.innerHTML = "<b>Hello World</b>";

}


</script>

<a href="javascript:createIt()">createIt</a>





</body></html>