• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 523
  • Last Modified:

Page scroll when using document.body.scrollTop

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
rdavis101
Asked:
rdavis101
  • 3
  • 2
1 Solution
 
NetGrooveCommented:
I remember this question with the same site.
The solution was the ";retern false" suffix.

Did you ask this question before?

0
 
NetGrooveCommented:
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
 
rdavis101Author Commented:
You guys have a better memory than I do. Thanks.
0
 
NetGrooveCommented:
Oh, then please take my apologize for bad assumptions :)

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

See you,
NetGroove

0
 
rdavis101Author Commented:
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now