Scrollto does not exactly stop in place (#idSection)

Asked

Viewed 50 times

2

I’m using the effect scrollTo tweenmax, however I’m having a problem, the site eh composed by a few sections each has an id that use anchor in scrollTo.

When I click on the menu the site slides (descends) until the Action I selected but it exceeds the start of the Service by staying on top of the h2.title and when I’m below that Action and I click so that it slides (up) until it the site does not stop at the same place that stopped when it descends. (strange because the anchor is the same)

The code I use is this:

$(function(){
  var wrapper = $("#wrapper"),
  $menu = $("#menu");

  $menu.on("click","li", function(){
    var $this = $(this),
        href = $(this).find("a").attr("href"),
        topY = $(href).offset().top;

      TweenLite.to(window, 2, {scrollTo:{y:topY, x:0}, ease:Cubic.easeIn});

    return false;
  });

});

I’ve tried to use y:topY -70for example but it did not work, it even gets -70px up but not solve my problem.

It would if he respected the very beginning of Ction.

Updated:

HTML looks something like this:

<div class="wrap">
  <nav>
    <ul>
      <li><a href="section-1">Section 1</a></li>
      <li><a href="section-2">Section 2</a></li>
      <li><a href="section-3">Section 3</a></li>
    </ul>
  </nav>
  
  <section id="section-1"> Conteudo 1</section>
   <section id="section-2"> Conteudo 2</section>
    <section id="section-3"> Conteudo 3</section>
</div>

Update 2

The menu when you touch the top of the browser gets fixed at the top, it is 70px high, so I put the y:topY -70 to discount, but tb n was cool, however if I take the fixed menu there works cool. oo

Update 3 - Fixed Menu

	// Menu fixo top
	var offset = $('#menu').offset().top;
	var $meuMenu = $('#menu');
	$(document).on('scroll', function () {
	    if (offset <= $(window).scrollTop()) {
	        $meuMenu.addClass('fixar');
	    } else {
	        $meuMenu.removeClass('fixar');
	    }
	});

Update 4 Follow the link to see in practice the error, thank you.

Link to the Website

  • How is the HTML?

  • I updated @user3453562

  • Dude, I don’t know this library, but I think it’s valid to try this way: $(e.target.hash). offset(). top for its vertical position.

  • @Almernakano I tried here but it did not roll =/

No answers

Browser other questions tagged

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