javascript onload not working but onclick is working css draw line

emertj

New Member
I am trying to draw a line with css and javascript as in the example here: example. I can get it to work just fine with the original stuff but after trying to modify it and then get it to work onload from the html onload equals its not working, but it is working with the onclick event.here is my css:\[code\].line { position: absolute; height: 0px; border-width: 2px 0px 0px 0px; border-style: solid; border-color: #99aadd; }\[/code\]and the javascript:\[code\]function createLine2(myline,x1,y1,x2,y2){ if (x2 < x1) { var temp = x1; x1 = x2; x2 = temp; temp = y1; y1 = y2; y2 = temp; } var length = Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); myline.style.width = length+"px"; var angle = Math.atan((y2-y1)/(x2-x1)); myline.style.top = y1 + 0.5*length*Math.sin(angle) + "px"; myline.style.left = x1 - 0.5*length*(1 - Math.cos(angle)) + "px"; myline.style.MozTransform = myline.style.WebkitTransform = myline.style.OTransform="rotate("+angle+"rad)";}\[/code\]and finally the html that does not work:\[code\]<div class="line" onload="createLine2(this,100,100,0,0)">test</div><br>\[/code\]and the html that does work:\[code\]<div class="line" onclick="createLine2(this,100,100,0,0)">test</div><br>\[/code\]How do I get it to work with onload and what did I mess up?
 
Back
Top