scroll the page from the beginning to the designated position

Asked 1 years ago, Updated 1 years ago, 36 views

This site (http://play-in-hell.com/) displays from the bottom when the page transitions.
How do I display the top page from this location?

What I want to do is to make sure that there is an image on the front page so that the bottom part of the image can be seen.Depending on the browser display and the resolution of the display, the bottom part of the image may be hidden, so if it is hidden, I think it will not be possible to scroll a little.

I look forward to your kind cooperation.

javascript jquery html css

2022-09-29 21:40

2 Answers

To display at the bottom, you can implement it with the following code:

window.scrollTo(0, document.body.scrollHeight);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<h1>Top>/h1>

<img id="screenshot" width="500" height="955" src="http://i.stack.imgur.com/gRkqm.png">/img>

<h1>bottom</h1>

Note: I used @h2so5's HTML in the snippet.Thank you.


2022-09-29 21:40

Scroll itself is possible using scrollTop(), so you can calculate the coordinates of the image.

$(function(){
  var$img=$('#screenshot');
  varbottom=$img.offset().top+$img.height();
  var height=$(window).height();
  if(bottom>height)
    $(document).scrollTop(bottom-height);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<h1>Top>/h1>

<img id="screenshot" width="500" height="955" src="http://i.stack.imgur.com/gRkqm.png">/img>

<h1>bottom</h1>


2022-09-29 21:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.