Click to See Complete Forum and Search --> : Disabling mouse effects?!?!


BattleGuard
08-31-2003, 10:08 AM
Hi, I have a mouse effect from this site here's the script:

http://www.dynamicdrive.com/dynamicindex13/star3.htm

Scroll down to the bottom and that the script. It's a magic wand mouse cursor. Now my question is, is there a way to disable and enable these effect just by the push of a button.. Something like when you press the button, change a variable from yes to no, and when you press again, change the variable and the variable controls if the script is carried out or not... is there a way to do this?? Thanx a bunch!!

BattleGuard

Khalid Ali
08-31-2003, 10:48 AM
decalre a global variable at the very beginning of your script e.g

var timer;


just like above then locate this line of the code

setTimeout("animateLogo()", 10);

and replace it with this

timer = setTimeout("animateLogo()", 10);

now create a function e.g

function toggleAnimation(obj){
if(obj.value=="Start"){
animateLogo();
obj.value = "Stop";
}else{
obj.value = "Start";
clearTimeout(timer);
}
}

now in the html part of the page

add this button anywhere

<input type="button" value="Stop" onclick="toggleAnimation(this)"/>



this should do it..:D

BattleGuard
08-31-2003, 11:08 AM
Thank you Khalid!! But I have one question before implementing your code. I'm not very familiar with JS, so where do I declare a global variable, and how? Should I just put it at the very beginning of the whole code? Or at the beginning of the mouse effects code?? And do I just put var timer;?? Thanx

BatleGuard

Khalid Ali
08-31-2003, 11:21 AM
use this

<script type="text/javascript">
var timer;

function toggleAnimation(obj){
if(obj.value=="Start"){
animateLogo();
obj.value = "Stop";
}else{
obj.value = "Start";
clearTimeout(timer);
}
}

</script>

put the above before any other script so that from head tag down the above is the first script statement.