Solved

Page scroll when using document.body.scrollTop

Posted on 2003-10-31
5
515 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

930 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

16 Experts available now in Live!

Get 1:1 Help Now