Solved

define an integer variable appended with px

Posted on 2006-06-10
3
957 Views
Last Modified: 2012-08-13
basically the script below modifies some CSS to scroll down a div menu, the problem is it doesnt seem to scroll down in pixels ( if i change for example "(<37)" to "(<36)" the layer actually repositions by roughly 10pixels.

var i=-150;
var intHide;

function show()
{
if (i<37)
      {
      i=i+4;
      document.all("foo").style.top=i-1;
      }
}

function showmenu()
{
clearInterval(intHide);
intShow=setInterval("show()",1);
}

function hide()
{
if (i>-150)
      {
      i=i-4;
      document.all("foo").style.top=i;
      }
}

function hidemenu()
{
clearInterval(intShow);
intHide=setInterval("hide()",1);
}
0
Comment
Question by:webwolf_3000
  • 2
3 Comments
 
LVL 63

Accepted Solution

by:
Zvonko earned 300 total points
Comment Utility
9*4 = 36
So when you let the limit be 37 you jump one step further to 10*4
 Comment the 4-step out and look for the pixel behavior:
   // i=i+4;

0
 
LVL 5

Author Comment

by:webwolf_3000
Comment Utility
nice, thanks for the tip-off :)

if (i<39)
      {
      i=i+4;
      document.all("foo").style.top=i-3;
                }

you have earned the points:

just to clarify, where did you get 9*4=36 based on the script ?
i see the *4 is from i+i=4;
i understand the mathematics behind the problem ( thanks to your explanation ),
i just dont see where the 9* comes into it.

0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
Sorry, the guess with nine was wrong. You start from minus 150 and go to 36 or 37. Therefore you have either 46 or 47 steps each 4 pixels.

0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now