Solved

Page scroll when using document.body.scrollTop

Posted on 2003-10-31
5
513 Views
Last Modified: 2010-08-05
Please check www.VisionSimulations.com. I want to show a full size image when the user clicks a thumbnail on the right. I want to show the image in the middle of the viewport, so I need to find out if the page is scrolled. Scroll down to the bottom of www.VisionSimulations.com and then click an image. You'll see that the page scrolls back to the top. It's as if positioning the ShowImagesDiv causes the page to scroll back. Below is the javascript.

Why does this happen and how can I prevent it?

Roger

function ShowImage(stPicture, iWidth, iHeight)
  {
  stPicture="url(" + stPicture + ")" ;
  iLeft = document.body.clientWidth/2-iWidth/2;
  document.getElementById("ShowImagesDIV").style.left=iLeft ;
  //document.getElementById("ShowImagesDIV").style.top=document.body.scrollTop + document.body.clientHeight/2 - iHeight/2;
  document.getElementById("ShowImagesDIV").style.top=document.body.scrollTop;
  document.getElementById("ShowImagesDIV").style.width=iWidth;
  document.getElementById("ShowImagesDIV").style.height=iHeight;
  document.getElementById("ShowImagesDIV").style.background=stPicture;
  document.getElementById("ShowImagesDIV").style.visibility="visible" ;
  return false;
  }
0
Comment
Question by:rdavis101
  • 3
  • 2
5 Comments
 
LVL 10

Expert Comment

by:NetGroove
ID: 9659296
I remember this question with the same site.
The solution was the ";retern false" suffix.

Did you ask this question before?

0
 
LVL 10

Accepted Solution

by:
NetGroove earned 125 total points
ID: 9659320
I found your question:
http://oldlook.experts-exchange.com/Web/Web_Languages/JavaScript/Q_20733806.html

Could it be you are catching hits here?
Or do you remember Alsheimer?

0
 

Author Comment

by:rdavis101
ID: 9659365
You guys have a better memory than I do. Thanks.
0
 
LVL 10

Expert Comment

by:NetGroove
ID: 9659392
Oh, then please take my apologize for bad assumptions :)

Thanks for the points (in spite of my typo!)

See you,
NetGroove

0
 

Author Comment

by:rdavis101
ID: 9659407
Oops...I accepted the answer and just assumed I'd made a stupid mistake. But, that doesn't seem to be the case, since return false; is in the code.

So what's the deal?

Roger
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 how to create an extensible mechanism for linked drop downs.
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…

707 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