www.webdeveloper.com
Results 1 to 7 of 7

Thread: javascript wtf

  1. #1
    Join Date
    Jul 2009
    Posts
    70

    Exclamation javascript wtf

    Code:
    var $pixel=2;
    function $space(){
    spool=setInterval("$time()", 100);
    }
    
    function $time(){
    $pixel+=2;
    document.getElementById("move").style.marginLeft=$pixel+"px";
    clearInterval(spool);
    if($pixel==70){
    clearInterval(spool);
    }}
    um i cant get this to work but im really confused by the fact that when i scroll my mouse over the link very fast multiple times it seems to break and just keep going does anyone know why?

  2. #2
    Join Date
    Oct 2003
    Location
    Andover, UK
    Posts
    945
    What events are you using to detect mouseover?

    And why do you clear the interval, then clear it again (which will error, since you've already killed it) conditionally?

    Code:
    clearInterval(spool);
    if($pixel==70){
    clearInterval(spool);

  3. #3
    Join Date
    Jul 2009
    Posts
    70
    i realise i stopped it twice but i was still confused. The
    Code:
    if($pixel==70){clearInterval(spool);
    part on its own doesnt stop the menu bar it just keeps rolling to the right. I used
    Code:
    onmouseover
    to call
    Code:
    function $space(){
    I cant seem to cancel the loop without it either instantly moving seventy pixels to the left or causing my browser to crash.

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Just a note: as far as I know, javascript functions and variables can contain only alphanumeric characters (alphabet and digits) and the underscore. Also, the name cannot begin with a numeral. I would have avoid using $ within the name of functions and variables. After all it is javascript, not php

  5. #5
    Join Date
    Jul 2009
    Posts
    70
    thanks ill use _ from now on then

  6. #6
    Join Date
    Jul 2003
    Location
    The City of Roses
    Posts
    2,503
    The dollar sign is actually a perfectly valid character, and it can be used anywhere in a variable name. We might choose to not use it for stylistic reasons, but there is no practical reason to avoid it.
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

  7. #7
    Join Date
    Oct 2003
    Location
    Andover, UK
    Posts
    945
    The dollar sign is actually a perfectly valid character
    Indeed, otherwise JQuery wouldn't work. I agree, though, stylistically it should be avoided in JS.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles