Scroll to the button

Asked

Viewed 5,471 times

2

I need to get the user to click on div with class panel-heading (h2), scroll down from the screen to the link sitebusca.html/. How can I create this code?

HTML:

<div class="panel panel-default pulse animated">
  <span class="side-tab" data-target="#tab1" data-toggle="tab" role="tab"
  aria-expanded="false">
    <div class="panel-heading" role="tab" id="headingOne" data-toggle="collapse"
    data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
      <div class="text-pan animated bounce">
        <i class="glyphicon glyphicon-map-marker gly-circle">
        </i>
      </br>
      <h2 id="title-cat">
        Título Collapse
      </h2>
    </div>
  </div>
</span>
<div id="collapseOne" class="panel-collapse collapse" role="tabpanel"
aria-labelledby="headingOne">
  <div id="panel-mob" style="margin-bottom: 50px;">
    <div class="thumbnail">
      <img data-src="holder.js/100%x200" alt="100%x200" src="imagens/background/bg-mob-one.jpg">
      <div class="caption-mob panel-body">
        <h3 class="caption-title-mob animated fadeInDown">
          TESTE NOVO SITE
        </h3>
        <p class="caption-text-mob animated fadeInDown">
          Sub descrição
        </p>
        <center>
          <a href="sitebusca.html/" class="btn btn-success btn-lg btn-config btn-mob animated fadeInLeft">
            acessar »
          </a>
        </center>
      </div>
    </div>
  </div>
</div>
</div>

2 answers

1

Use anchors. For example:

<style>
#panel-heading{
  height: 300px;
  width: 600px;
  background-color: grey;
  padding: 20px;
}
</style>
<a href="#panel-heading">descer página<a><br><br><br><br><br><br><br><br><br><br>
<div id="panel-heading">Conteúdo</div>

Or

<script type="text/javascript">
    function rolar(objID) {
        this.location = "#" + objID;
    }
</script>


    <div onclick="rolar('panel-heading');"></div><br><br><br><br><br><br><br><br><br><br>

    <div id="panel-heading">Conteúdo</div>
  • Carlos, I already did this test. But I can’t use the "href" tag, because I’m working with a div. I need the person to click on the div that contains the panel-Heading class, and the page will scroll down to the button with that link. Downloaded?

  • Look at a solution with Javascript, edited. But what will be inside this div ? If it is only text/image could do using link.

  • Carlos, I was able to insert. However, the effect is very hard. How can I apply a jquery effect. As for example: easeInOutExpo ?

1

I think it would be better to make a solution purely with Javascript, so avoid soiling the html with functions within elements. Change the pro classes/ids you prefer:

$('.click-scroll').click(function () {
    $('html, body').animate({
        scrollTop: $("#alvo").offset().top
        }, 2000); // Tempo em ms que a animação irá durar
});
  • But what if the clicked button is a link ? how to make the page not reload ?

Browser other questions tagged

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