?
Solved

define an integer variable appended with px

Posted on 2006-06-10
3
Medium Priority
?
967 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:Gareth Pritchard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 63

Accepted Solution

by:
Zvonko earned 1200 total points
ID: 16876764
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:Gareth Pritchard
ID: 16876876
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
ID: 16876922
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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…
Suggested Courses

762 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