detta är ett script som ändrar bakgrundsfärgen när man
drar i ett lager.
Hur ska jag bete mig för att på onload dra det automatisk.
onload = dra id="knobImg1" till top 45px
alltså simulera en dragning av mus.
<html>
<head>
<title>Untitled Document</title>
<style>.drag {position: relative; cursor: hand}</style>
<SCRIPT LANGUAGE="JavaScript1.2">
var sPosition;
var showPerc=100;
document.onmousedown=dragLayer
document.onmouseup=new Function("dragMe=false")
var Color= new Array();
Color[0] = "00";
Color[1] = "11";
Color[2] = "22";
Color[3] = "33";
Color[4] = "44";
Color[5] = "55";
Color[6] = "66";
Color[7] = "77";
Color[8] = "88";
Color[9] = "99";
Color[10] = "AA";
Color[11] = "BB";
Color[12] = "CC";
Color[13] = "DD";
Color[14] = "EE";
Color[15] = "FF";
var rVal,gVal,bVal, cCol, cCol2
function chgBg() {
cCol = document.bgColor; rVal=cCol.substr(1,2); gVal=cCol.substr(3,2); bVal=cCol.substr(5,2);
ind = Math.round(showPerc/16); if (ind \< 0) ind = 0; if (ind \> 15) ind=15;
if (kObj.id =="knobImg") document.bgColor="#"+Color[ind]+gVal+bVal;
}
var dragMe=false, kObj, yPos,direction
function moveLayer(who) {
if (event.button==1 && dragMe) {
oldY = kObj.style.pixelTop; kObj.style.pixelTop=temp2+event.clientY-yPos;
if (kObj.style.pixelTop \> oldY) direction="dn"; else direction="up";
if (kObj.style.pixelTop \< 2 && direction=="up") {kObj.style.pixelTop=2; direction="dn";}
if (kObj.style.pixelTop \> 102 && direction=="dn") {kObj.style.pixelTop=102; direction="up";}
sPosition=kObj.style.pixelTop; showPerc = (perCent\[0\].checked) ? sPosition-2 : (sPosition-2)/2\*5;
chgBg(who);
return false; }
}
function dragLayer() {
if (!document.all) return;
if (event.srcElement.className=="drag") {dragMe=true; kObj=event.srcElement; temp2=kObj.style.pixelTop; yPos=event.clientY; document.onmousemove=moveLayer; }
}
</script>
</head>
<body>
<div id="outerLyr" style="position:absolute; width:23px; height:120px; z-index:1; left: 200px; top: 111px; background-color: #000000">
<img src="knob.gif" width="20" height="17" class="drag" id="knobImg" style="width: 20px; height: 17px; z-index:3; left: 2px; top: 100px">
<div id="innerLyr" style="position:absolute; width:20px; height:117px; z-index:2; background-color: #777777; left: 2px; top: 2px">
<div id="barLyr" style="position:absolute; width:2px; height:110px; z-index:1; background-color: #000000; left: 9px; top: 5px"></div>
</div>
</div>
<input type="radio" name="perCent" value="false">
100
<input type="radio" name="perCent" value="true" checked>255
</body>
</html>