2016-12-30 69 views
5

我正在編寫一個網站,我想構建一些窗口大小的div /節。當用戶停止在這兩個div之間滾動時,需要更多空間的div應在滾動,因此它將是全窗口大小。滾動後滾動到下一個錨點

+0

似乎你loooking爲[fullPage.js(http://alvarotrigo.com重新實現邏輯/ fullPage /)但保持滾動條?看看[這個演示](http://alvarotrigo.com/fullPage/examples/normalScroll.html)或[this other one](http://alvarotrigo.com/fullPage/examples/scrollBar.html)。 – Alvaro

回答

1

有jQuery插件做到這一點,但這裏有一個很好的模板,以瞭解如何實現自己:

https://startbootstrap.com/template-overviews/scrolling-nav/

這裏的相關滾動JavaScript的easing功能,使其很好,可滾動:

//jQuery to collapse the navbar on scroll 
$(window).scroll(function() { 
    if ($(".navbar").offset().top > 50) { 
     $(".navbar-fixed-top").addClass("top-nav-collapse"); 
    } else { 
     $(".navbar-fixed-top").removeClass("top-nav-collapse"); 
    } 
}); 

//jQuery for page scrolling feature - requires jQuery Easing plugin 
$(function() { 
    $('a.page-scroll').bind('click', function(event) { 
     var $anchor = $(this); 
     $('html, body').stop().animate({ 
      scrollTop: $($anchor.attr('href')).offset().top 
     }, 1500, 'easeInOutExpo'); 
     event.preventDefault(); 
    }); 
});