bamben
06-25-2009, 02:02 PM
Hi all! I am new to javascript (I seam to be getting it right so far). I modifyed a java script that scrolled up and down on a page into a really cool script that builds a box around your website (unobtrusive). Now the script lets a user scroll in all directions including diaganol (all on mouse over) and double click makes it jump faster if you are in a hurry lol....
problem: I have been working really hard at making a button that toggles this script on and off (when off the scroll should be totally locked). I cant get my head around it though because my fuction playscroll() is called in the script at the very bottom (so this is like onload playscroll), to make a button that stops this is .... well I dont understand how I would do it because I would have to maybe first take this playscroll() code out and put it in my button like playscroll=true/playscroll=false ( but I like it set to scroll when loaded as it is now ) also the on mouse overs are making it difficult for me to get my head around ie: how the hell do I stop them lol!
Basicly: I love my script as it is now, only I really need to make a button that locks/un-locks the scroll
<script>
// *** D E F I N E V A R I A B L E S ***
// PUT YOUR CONTENT FILE
var filecontent = "http://www.mysite.com"; // put your content file
// SCROLLER OUTER BORDER IN PIXEL
var scrollborder = "1px";
var scrollbordercolor = "#CCCCCC";
// SCROLLBOX SIZE IN PIXEL:[999]px OR PERSENTAGE:[1-100]%
var scrollwidth = "94.7%";
var scrollheight = "94.3%";
// FILE NAVIGATION IMAGES (left & right) ATTRIBUTES
var imgleft = "scroll.png";
var imgright = "scroll.png";
var imgup = "scroll.png";
var imgdown = "scroll.png";
var imgwidth = "100%";
var imgheight = "100%";
// *** S T A R T S C R I P T ***
var TIME=9;
function LEFT(){
PAGE.scrollBy(-20,0);TIME=setTimeout('LEFT()',20);
}
function RIGHT(){
PAGE.scrollBy(20,0);TIME=setTimeout('RIGHT()',20);
}
function UP(){
PAGE.scrollBy(0,-20);TIME=setTimeout('UP()',20);
}
function DOWN(){
PAGE.scrollBy(0,20);TIME=setTimeout('DOWN()',20);
}
function DiDL(){
PAGE.scrollBy(-20,20);TIME=setTimeout('DiDL()',20);
}
function DiDR(){
PAGE.scrollBy(20,20);TIME=setTimeout('DiDR()',20);
}
function DiUR(){
PAGE.scrollBy(20,-20);TIME=setTimeout('DiUR()',20);
}
function DiUL(){
PAGE.scrollBy(-20,-20);TIME=setTimeout('DiUL()',20);
}
function STOP() {
clearTimeout(TIME);
}
function boxanak(){
var boxwidth=
document.writeln('<iframe name="PAGE" frameborder="1" scrolling="no" src="'+filecontent+'" style="position:absolute; width:94.7%; height:94.5%; border:1px outset #00CCFF; z-index:1; left: 2.5%; top: 2.5%; color:#FF0000; z-index:3;"></iframe>');
}
function playscroll(){
boxanak();
document.writeln('<div id="LEFT" style="position:absolute; width:2.5%; height:95%; z-index:1; top: 2.5%; left: 0; border: 1px none #000000;">');
document.writeln('<img class="klik" style="cursor:hand" src="'+ imgleft +'" border="0" width="'+ imgwidth +'" height="'+ imgheight +'" onmouseover="LEFT()" onmouseout="STOP()" onClick="PAGE.scrollBy(-200,0)">');
document.writeln('</div>');
document.writeln('<div id="LEFTlable" style="position:absolute; width:2.5%; height:50%; z-index:0; top: 50%; left: 0; background-color: #000000; layer-background-color: #000000; border: 1px none #000000;">');
document.writeln('<center><span align="middle" style="color: #FF0000; font-family: Tahoma, Impact;font-size: 10;";><</span></center>');
document.writeln('</div>');
document.writeln('<div id="LEFTfill" style="position:absolute; width:2.5%; height:100%; z-index:-1; top: 0%; left: 0%; background-color: #000000; layer-background-color: #000000; border: 1px none #000000;"></div>');
document.writeln('<div id="RIGHT" style="position:absolute; width:2.5%; height:95%; z-index:1; top: 2.5%; left: 97.5%; border: 1px none #000000;">');
document.writeln('<img class="klik" style="cursor:hand" src="'+ imgright +'" border="0" width="'+ imgwidth +'" height="'+ imgheight +'" onmouseover="RIGHT()" onmouseout="STOP()" onClick="PAGE.scrollBy(200,0)">');
document.writeln('</div>');
document.writeln('<div id="RIGHTlable" style="position:absolute; width:2.5%; height:50%; z-index:0; top: 50%; left: 97.5%; background-color: #000000; layer-background-color: #000000; border: 1px none #000000;">');
document.writeln('<center><span align="middle" style="color: #FF0000; font-family: Tahoma, Impact;font-size: 10;";>></span></center>');
document.writeln('</div>');
document.writeln('<div id="RIGHTfill" style="position:absolute; width:2.5%; height:100%; z-index:-1; top: 0%; left: 97.5%; background-color: #000000; layer-background-color: #000000; border: 1px none #000000;"></div>');
document.writeln('<div id="UP" style="position:absolute; width:95%; height:2.5%; z-index:1; left: 2.5%; top: 0; border: 1px none #000000;">');
document.writeln('<img class="klik" style="cursor:hand" src="'+ imgup +'" border="0" width="'+ imgwidth +'" height="'+ imgheight +'" onmouseover="UP()" onmouseout="STOP()" onClick="PAGE.scrollBy(0,-200)">');
document.writeln('</div>');
document.writeln('<div id="UPlable" style="position:absolute; width:95%; height:2.5%; z-index:0; left: 2.5%; top: 0; background-color: #000000; layer-background-color: #000000; border: 1px none #000000;">');
document.writeln('<center><span style="color: #FF0000; font-family: Tahoma, Impact;font-size: 10;";> CLICK SCROLL </span></center>');
document.writeln('</div>');
document.writeln('<div id="DOWN" style="position:absolute; width:95%; height:2.5%; z-index:1; left: 2.5%; top: 97.5%; border: 1px none #000000;">');
document.writeln('<img class="klik" style="cursor:hand" src="'+ imgdown +'" border="0" width="'+ imgwidth +'" height="'+ imgheight +'" onmouseover="DOWN()" onmouseout="STOP()" onClick="PAGE.scrollBy(0,200)">');
document.writeln('</div>');
document.writeln('<div id="DOWNlable" style="position:absolute; width:95%; height:2.5%; z-index:0; left: 2.5%; top: 97.5%; background-color: #000000; layer-background-color: #000000; border: 1px none #000000;">');
document.writeln('<center><span style="color: #FF0000; font-family: Tahoma, Impact;font-size: 10;";> CLICK SCROLL </span></center>');
document.writeln('</div>');
document.writeln('<div id="DIDL" style="position:absolute; width:25%; height:2.5%; z-index:2; left: 0%; top: 97.5%; background-color: #000000; layer-background-color: #FF0000; border: 1px none #000000;">');
document.writeln('<img class="klik" style="cursor:hand" src="'+ imgdown +'" border="0" width="'+ imgwidth +'" height="'+ imgheight +'" onmouseover="DiDL()" onmouseout="STOP()" onClick="PAGE.scrollBy(-200,200)">');
document.writeln('</div>');
document.writeln('<div id="DIDL2" style="position:absolute; width:2.5%; height:25%; z-index:3; left: 0%; top: 75%; background-color: #000000; layer-background-color: #FF0000; border: 1px none #000000;">');
document.writeln('<img class="klik" style="cursor:hand" src="'+ imgdown +'" border="0" width="'+ imgwidth +'" height="'+ imgheight +'" onmouseover="DiDL()" onmouseout="STOP()" onClick="PAGE.scrollBy(-200,200)">');
document.writeln('</div>');
document.writeln('<div id="DIDR" style="position:absolute; width:25%; height:2.5%; z-index:2; left: 75%; top: 97.5%; background-color: #000000; layer-background-color: #FF0000; border: 1px none #000000;">');
document.writeln('<img class="klik" style="cursor:hand" src="'+ imgdown +'" border="0" width="'+ imgwidth +'" height="'+ imgheight +'" onmouseover="DiDR()" onmouseout="STOP()" onClick="PAGE.scrollBy(200,200)">');
document.writeln('</div>');
document.writeln('<div id="DIDR2" style="position:absolute; width:2.5%; height:25%; z-index:3; left: 97.5%; top: 75%; background-color: #000000; layer-background-color: #FF0000; border: 1px none #000000;">');
document.writeln('<img class="klik" style="cursor:hand" src="'+ imgdown +'" border="0" width="'+ imgwidth +'" height="'+ imgheight +'" onmouseover="DiDR()" onmouseout="STOP()" onClick="PAGE.scrollBy(200,200)">');
document.writeln('</div>');
document.writeln('<div id="DIUR" style="position:absolute; width:25%; height:2.5%; z-index:2; left: 75%; top: 0%; background-color: #000000; layer-background-color: #FF0000; border: 1px none #000000;">');
document.writeln('<img class="klik" style="cursor:hand" src="'+ imgdown +'" border="0" width="'+ imgwidth +'" height="'+ imgheight +'" onmouseover="DiUR()" onmouseout="STOP()" onClick="PAGE.scrollBy(200,-200)">');
document.writeln('</div>');
document.writeln('<div id="DIUR2" style="position:absolute; width:2.5%; height:25%; z-index:3; left: 97.5%; top: 0%; background-color: #000000; layer-background-color: #FF0000; border: 1px none #000000;">');
document.writeln('<img class="klik" style="cursor:hand" src="'+ imgdown +'" border="0" width="'+ imgwidth +'" height="'+ imgheight +'" onmouseover="DiUR()" onmouseout="STOP()" onClick="PAGE.scrollBy(200,-200)">');
document.writeln('</div>');
document.writeln('<div id="DIUL" style="position:absolute; width:25%; height:2.5%; z-index:2; left: 0%; top: 0%; background-color: #000000; layer-background-color: #FF0000; border: 1px none #000000;">');
document.writeln('<img class="klik" style="cursor:hand" src="'+ imgdown +'" border="0" width="'+ imgwidth +'" height="'+ imgheight +'" onmouseover="DiUL()" onmouseout="STOP()" onClick="PAGE.scrollBy(-200,-200)">');
document.writeln('</div>');
document.writeln('<div id="DIUL2" style="position:absolute; width:2.5%; height:25%; z-index:3; left: 0%; top: 0%; background-color: #000000; layer-background-color: #FF0000; border: 1px none #000000;">');
document.writeln('<img class="klik" style="cursor:hand" src="'+ imgdown +'" border="0" width="'+ imgwidth +'" height="'+ imgheight +'" onmouseover="DiUL()" onmouseout="STOP()" onClick="PAGE.scrollBy(-200,-200)">');
document.writeln('</div>');
}
playscroll();
</script>
http://www.dynamicdrive.com (this is nothing)
problem: I have been working really hard at making a button that toggles this script on and off (when off the scroll should be totally locked). I cant get my head around it though because my fuction playscroll() is called in the script at the very bottom (so this is like onload playscroll), to make a button that stops this is .... well I dont understand how I would do it because I would have to maybe first take this playscroll() code out and put it in my button like playscroll=true/playscroll=false ( but I like it set to scroll when loaded as it is now ) also the on mouse overs are making it difficult for me to get my head around ie: how the hell do I stop them lol!
Basicly: I love my script as it is now, only I really need to make a button that locks/un-locks the scroll
<script>
// *** D E F I N E V A R I A B L E S ***
// PUT YOUR CONTENT FILE
var filecontent = "http://www.mysite.com"; // put your content file
// SCROLLER OUTER BORDER IN PIXEL
var scrollborder = "1px";
var scrollbordercolor = "#CCCCCC";
// SCROLLBOX SIZE IN PIXEL:[999]px OR PERSENTAGE:[1-100]%
var scrollwidth = "94.7%";
var scrollheight = "94.3%";
// FILE NAVIGATION IMAGES (left & right) ATTRIBUTES
var imgleft = "scroll.png";
var imgright = "scroll.png";
var imgup = "scroll.png";
var imgdown = "scroll.png";
var imgwidth = "100%";
var imgheight = "100%";
// *** S T A R T S C R I P T ***
var TIME=9;
function LEFT(){
PAGE.scrollBy(-20,0);TIME=setTimeout('LEFT()',20);
}
function RIGHT(){
PAGE.scrollBy(20,0);TIME=setTimeout('RIGHT()',20);
}
function UP(){
PAGE.scrollBy(0,-20);TIME=setTimeout('UP()',20);
}
function DOWN(){
PAGE.scrollBy(0,20);TIME=setTimeout('DOWN()',20);
}
function DiDL(){
PAGE.scrollBy(-20,20);TIME=setTimeout('DiDL()',20);
}
function DiDR(){
PAGE.scrollBy(20,20);TIME=setTimeout('DiDR()',20);
}
function DiUR(){
PAGE.scrollBy(20,-20);TIME=setTimeout('DiUR()',20);
}
function DiUL(){
PAGE.scrollBy(-20,-20);TIME=setTimeout('DiUL()',20);
}
function STOP() {
clearTimeout(TIME);
}
function boxanak(){
var boxwidth=
document.writeln('<iframe name="PAGE" frameborder="1" scrolling="no" src="'+filecontent+'" style="position:absolute; width:94.7%; height:94.5%; border:1px outset #00CCFF; z-index:1; left: 2.5%; top: 2.5%; color:#FF0000; z-index:3;"></iframe>');
}
function playscroll(){
boxanak();
document.writeln('<div id="LEFT" style="position:absolute; width:2.5%; height:95%; z-index:1; top: 2.5%; left: 0; border: 1px none #000000;">');
document.writeln('<img class="klik" style="cursor:hand" src="'+ imgleft +'" border="0" width="'+ imgwidth +'" height="'+ imgheight +'" onmouseover="LEFT()" onmouseout="STOP()" onClick="PAGE.scrollBy(-200,0)">');
document.writeln('</div>');
document.writeln('<div id="LEFTlable" style="position:absolute; width:2.5%; height:50%; z-index:0; top: 50%; left: 0; background-color: #000000; layer-background-color: #000000; border: 1px none #000000;">');
document.writeln('<center><span align="middle" style="color: #FF0000; font-family: Tahoma, Impact;font-size: 10;";><</span></center>');
document.writeln('</div>');
document.writeln('<div id="LEFTfill" style="position:absolute; width:2.5%; height:100%; z-index:-1; top: 0%; left: 0%; background-color: #000000; layer-background-color: #000000; border: 1px none #000000;"></div>');
document.writeln('<div id="RIGHT" style="position:absolute; width:2.5%; height:95%; z-index:1; top: 2.5%; left: 97.5%; border: 1px none #000000;">');
document.writeln('<img class="klik" style="cursor:hand" src="'+ imgright +'" border="0" width="'+ imgwidth +'" height="'+ imgheight +'" onmouseover="RIGHT()" onmouseout="STOP()" onClick="PAGE.scrollBy(200,0)">');
document.writeln('</div>');
document.writeln('<div id="RIGHTlable" style="position:absolute; width:2.5%; height:50%; z-index:0; top: 50%; left: 97.5%; background-color: #000000; layer-background-color: #000000; border: 1px none #000000;">');
document.writeln('<center><span align="middle" style="color: #FF0000; font-family: Tahoma, Impact;font-size: 10;";>></span></center>');
document.writeln('</div>');
document.writeln('<div id="RIGHTfill" style="position:absolute; width:2.5%; height:100%; z-index:-1; top: 0%; left: 97.5%; background-color: #000000; layer-background-color: #000000; border: 1px none #000000;"></div>');
document.writeln('<div id="UP" style="position:absolute; width:95%; height:2.5%; z-index:1; left: 2.5%; top: 0; border: 1px none #000000;">');
document.writeln('<img class="klik" style="cursor:hand" src="'+ imgup +'" border="0" width="'+ imgwidth +'" height="'+ imgheight +'" onmouseover="UP()" onmouseout="STOP()" onClick="PAGE.scrollBy(0,-200)">');
document.writeln('</div>');
document.writeln('<div id="UPlable" style="position:absolute; width:95%; height:2.5%; z-index:0; left: 2.5%; top: 0; background-color: #000000; layer-background-color: #000000; border: 1px none #000000;">');
document.writeln('<center><span style="color: #FF0000; font-family: Tahoma, Impact;font-size: 10;";> CLICK SCROLL </span></center>');
document.writeln('</div>');
document.writeln('<div id="DOWN" style="position:absolute; width:95%; height:2.5%; z-index:1; left: 2.5%; top: 97.5%; border: 1px none #000000;">');
document.writeln('<img class="klik" style="cursor:hand" src="'+ imgdown +'" border="0" width="'+ imgwidth +'" height="'+ imgheight +'" onmouseover="DOWN()" onmouseout="STOP()" onClick="PAGE.scrollBy(0,200)">');
document.writeln('</div>');
document.writeln('<div id="DOWNlable" style="position:absolute; width:95%; height:2.5%; z-index:0; left: 2.5%; top: 97.5%; background-color: #000000; layer-background-color: #000000; border: 1px none #000000;">');
document.writeln('<center><span style="color: #FF0000; font-family: Tahoma, Impact;font-size: 10;";> CLICK SCROLL </span></center>');
document.writeln('</div>');
document.writeln('<div id="DIDL" style="position:absolute; width:25%; height:2.5%; z-index:2; left: 0%; top: 97.5%; background-color: #000000; layer-background-color: #FF0000; border: 1px none #000000;">');
document.writeln('<img class="klik" style="cursor:hand" src="'+ imgdown +'" border="0" width="'+ imgwidth +'" height="'+ imgheight +'" onmouseover="DiDL()" onmouseout="STOP()" onClick="PAGE.scrollBy(-200,200)">');
document.writeln('</div>');
document.writeln('<div id="DIDL2" style="position:absolute; width:2.5%; height:25%; z-index:3; left: 0%; top: 75%; background-color: #000000; layer-background-color: #FF0000; border: 1px none #000000;">');
document.writeln('<img class="klik" style="cursor:hand" src="'+ imgdown +'" border="0" width="'+ imgwidth +'" height="'+ imgheight +'" onmouseover="DiDL()" onmouseout="STOP()" onClick="PAGE.scrollBy(-200,200)">');
document.writeln('</div>');
document.writeln('<div id="DIDR" style="position:absolute; width:25%; height:2.5%; z-index:2; left: 75%; top: 97.5%; background-color: #000000; layer-background-color: #FF0000; border: 1px none #000000;">');
document.writeln('<img class="klik" style="cursor:hand" src="'+ imgdown +'" border="0" width="'+ imgwidth +'" height="'+ imgheight +'" onmouseover="DiDR()" onmouseout="STOP()" onClick="PAGE.scrollBy(200,200)">');
document.writeln('</div>');
document.writeln('<div id="DIDR2" style="position:absolute; width:2.5%; height:25%; z-index:3; left: 97.5%; top: 75%; background-color: #000000; layer-background-color: #FF0000; border: 1px none #000000;">');
document.writeln('<img class="klik" style="cursor:hand" src="'+ imgdown +'" border="0" width="'+ imgwidth +'" height="'+ imgheight +'" onmouseover="DiDR()" onmouseout="STOP()" onClick="PAGE.scrollBy(200,200)">');
document.writeln('</div>');
document.writeln('<div id="DIUR" style="position:absolute; width:25%; height:2.5%; z-index:2; left: 75%; top: 0%; background-color: #000000; layer-background-color: #FF0000; border: 1px none #000000;">');
document.writeln('<img class="klik" style="cursor:hand" src="'+ imgdown +'" border="0" width="'+ imgwidth +'" height="'+ imgheight +'" onmouseover="DiUR()" onmouseout="STOP()" onClick="PAGE.scrollBy(200,-200)">');
document.writeln('</div>');
document.writeln('<div id="DIUR2" style="position:absolute; width:2.5%; height:25%; z-index:3; left: 97.5%; top: 0%; background-color: #000000; layer-background-color: #FF0000; border: 1px none #000000;">');
document.writeln('<img class="klik" style="cursor:hand" src="'+ imgdown +'" border="0" width="'+ imgwidth +'" height="'+ imgheight +'" onmouseover="DiUR()" onmouseout="STOP()" onClick="PAGE.scrollBy(200,-200)">');
document.writeln('</div>');
document.writeln('<div id="DIUL" style="position:absolute; width:25%; height:2.5%; z-index:2; left: 0%; top: 0%; background-color: #000000; layer-background-color: #FF0000; border: 1px none #000000;">');
document.writeln('<img class="klik" style="cursor:hand" src="'+ imgdown +'" border="0" width="'+ imgwidth +'" height="'+ imgheight +'" onmouseover="DiUL()" onmouseout="STOP()" onClick="PAGE.scrollBy(-200,-200)">');
document.writeln('</div>');
document.writeln('<div id="DIUL2" style="position:absolute; width:2.5%; height:25%; z-index:3; left: 0%; top: 0%; background-color: #000000; layer-background-color: #FF0000; border: 1px none #000000;">');
document.writeln('<img class="klik" style="cursor:hand" src="'+ imgdown +'" border="0" width="'+ imgwidth +'" height="'+ imgheight +'" onmouseover="DiUL()" onmouseout="STOP()" onClick="PAGE.scrollBy(-200,-200)">');
document.writeln('</div>');
}
playscroll();
</script>
http://www.dynamicdrive.com (this is nothing)