Solved

define an integer variable appended with px

Posted on 2006-06-10
3
963 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 300 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Review of the nodejs code 1 36
PHP: Filling Out/Creating a PDF 29 97
Find out all repos that a user is most active on Github 1 29
javascript form submition 2 21
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

749 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