Solved

# define an integer variable appended with px

Posted on 2006-06-10
957 Views
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;
}
}

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

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

{
clearInterval(intShow);
intHide=setInterval("hide()",1);
}
0
Question by:webwolf_3000
• 2

LVL 63

Accepted Solution

Zvonko earned 300 total points
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

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

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

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…