Solved

define an integer variable appended with px

Posted on 2006-06-10
3
962 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
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:webwolf_3000
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Javascript/JQuery - HtmlEncode (?) Ajax Result 1 66
jQuery Scroll To Top 5 38
Override MS CSS in SharePoint Online Modal Form 19 45
Responsive Font Size 6 29
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

828 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