Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Junior Member
    Join Date
    Dec 2007
    Posts
    8
    Member #
    16238
    So im trying to make a DIV move down and then stop at a point but no matter what i try I cannot make
    it pickup when its at a point. Im making it move down with a timer. Heres the code:

    if (document.getElementById('specials').style.left > "100px")
    {
    clearInterval(moveit);
    }

    But that doesnt work. It never becomes true. Ive also tried 100 without the "".

    Please could you help me, I would really appreciate it.

    Thanks in advance!

  2.  

  3. #2
    Senior Member hyperair's Avatar
    Join Date
    May 2005
    Posts
    452
    Member #
    9892
    You cannot use ">" to compare strings in that manner. String comparisons are an entirely different thing from numbers. They are used for determining a string's position in a sorted list. For example, in a list of sorted strings, you will get something like this: 1,10,100,2,20,200.... as opposed to 1,2,3,4..10....20....100....200.

    What you can do however... is use parseInt(). This will take a string argument and grab whatever numbers that it can find in it, and return an integer. In this case it would work perfectly:

    if (parseInt(document.getElementById('specials').styl e.left) > 100)
    {
    clearInterval(moveit);
    }

    I would, however like to inform you that this method is inefficient. Converting an image into a string when you set it as the style attribute, then converting it back into an integer simply isn't the best way to do things. I'm not sure that it would make a difference on the browser but when I do things like this I prefer to keep track of the variable in a certain other variable, that stays a number. This variable would then be used both for comparison and for calculations when shifting the element around. Perhaps if you post the full code, I can help you there. Anyway things like this don't really affect the browser much if done individually. However, if you do a massive page rendered entirely with Javascript and have many elements doing that effect, you may cause it to slowdown. At that point, every bit of optimisation you can do to your code becomes essential.
    Hyperair

  4. #3
    Junior Member
    Join Date
    Dec 2007
    Posts
    8
    Member #
    16238
    thanks so much! Its working perfectly now


    Thanks lot!

  5. #4
    Senior Member hyperair's Avatar
    Join Date
    May 2005
    Posts
    452
    Member #
    9892
    No problem.
    Hyperair


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:09 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com