Go to the bottom of the page

Asked

Viewed 2,279 times

3

Hi, I was wondering how you do to do when the person clicks, will go to the bottom of the page. If you can teach me I thank you!! In this case it was when clicked on some of these texts, http://prntscr.com/by6y69

  • To the very end? Or to a particular section?

  • For a section which in this case is a box http://prntscr.com/by742u

  • Are you using jquery? This does not do php, but javascript. You must add/replace javascript and jquery tags

1 answer

4


To scroll to the bottom of the page:

$('#down').on('click', function() {
  $('html, body').animate({
    scrollTop: $(document).height()
  }, 700);
});
#div1 {
 height: 1000px;
 background-color: red;
}
#div2 {
  height: 200px;
  background-color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="div1">
  <button id="down">IR LÁ PARA BAIXO</button>
</div>
<div id="div2"></div>

To scroll to a certain element:

var ele = $('#div2');
$('#down').on('click', function() {
  $('html, body').animate({
    scrollTop: ele.offset().top
  }, 700);
});
#div1 {
 height: 1000px;
 background-color: red;
}
#div2 {
  height: 800px;
  background-color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="div1">
  <button id="down">IR PARA DIV2</button>
</div>
<div id="div2"></div>

NOTE that in a real project in principle it is necessary to put the height on Ivs, as the height of these should be defined by their content

  • Where would I put this code?: var it = $('#div2'); $('#down'). on('click', Function() { $('html, body'). Animate({ scrollTop: ele.offset(). top }, 700); });

  • Inside the event you want to delegate to this, in my case it was within the click of the @Vinicius button. That is, the click on the button will happen this. You can just adjust the element to click, in my case it was the element whose id is down

  • I wanted to put in the case inside this code that is as described in the print: http://prntscr.com/by74y8 (Code: <li><a href="javascript:void(0);" onclick="getContentPage('topevent');"><span class="glyphicon glyphicon-Thumbs-up" style=" font-size: 10pt"></span Ranking </a></li>)

  • Can you change the HTML code @Vinicius? If so, do <a href="#" id="down">..., then in the line following }, 700); put a return false;

  • Miguel I have to tell you, I don’t know much about PHP or HTML so this complicates for me, I’m just not sure where to add this first code, because I wanted when I clicked on the ranking text to go to the end of the page (It seems easier) Only this, if you can explain me in an easier way than Voce can think I understand rs. I hope you don’t misunderstand.

  • Of course not @Vinicius. <a href="javascript:void(0);" onclick="getContentPage('topevent');"><span class="glyphicon glyphicon-thumbs-up" style=" font-size: 10pt"></span> Ranking </a> . Should stay: <a href="#" id="down"><span class="glyphicon glyphicon-thumbs-up" style=" font-size: 10pt"></span> Ranking </a> and then in the line following }, 700); in the js part I put, write return false; . This code must be placed inside the tag <script> and after importing jquery: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

  • 2 code is in css?

  • @Vinicius, here is the second example: https://jsfiddle.net/0dtsg39y/ . And here is the first: https://jsfiddle.net/0dtsg39y/1/

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.