Do not let the scroll stay in the middle, stay in one element or another

Asked

Viewed 83 times

1

Before too I wanted to apologize for the title of the question, I could not find a better way to explain. What I want is a 'normal' page, which has for example: 5 sections, I wanted in the scroll we did not see half of one and half of another, ie at the end of the event mousewhell or scroll 'manual', the page was emediatamente to the next or previous element (depending on the direction, up or down) but never between the two. my case in jsfiddle so far.

HTML:

<div id="acti1" class="acti" data-scrollTo="1"></div>
<div id="acti2" class="acti" data-scrollTo="2"></div>
<div id="acti3" class="acti" data-scrollTo="3"></div>
<div id="acti4" class="acti" data-scrollTo="4"></div>
<div id="acti5" class="acti" data-scrollTo="5"></div>

JS:

var navHeight = $('nav').height();
$('.acti').height($(window).height() - navHeight);

var rmLast = parseInt($('.acti').last().attr("data-scrollTo")) - 1;
$('.acti').slice(0, rmLast).click(function(){
    var scrollTo = parseInt($(this).attr("data-scrollTo"));
    $('body, html').stop().animate({
        scrollTop: $('.acti').eq(scrollTo).offset().top - navHeight
        });
    });

$(window).scroll(function(){
    ....
});
  • Miguel, if the scroll goes back for example to not let only half show how do you want it to be possible to pass to the next div? You want an elastic effect that "breaks" the next one if the scroll is "strong" enough?

  • Good morning @Die, it is dependent on the direction of the scroll, if you do go down goes to the bottom section up goes to the top section, in addition you would also like to put links on other pages that indicate to which section we would like it to be ex: index.php#section2 but not below the Nav bar, that is, it had to be index.php#section2 + Nav bar height (px)

  • Basically I wanted under no circumstances did we see two sections, or did we see the top or the bottom according to the scroll

  • But do you want some scroll or no scroll? If you don’t want scroll you could have a screen size page with Divs with position Fixed, top -1000px and then do css top Transitions for 0 of the div you want to see. That with scroll direction?

  • Look yes this stops being even the solution, but attention because there will be the navigation bar Fixed top as well, just like the jsfiddle that Linkei, but if scroll up appears the section above and vice versa, also will have two buttons to go to the sections above/below. Do you have a simple solution for this? Obragdo

No answers

Browser other questions tagged

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