滚动后滚动到下一个锚点

时间:2016-12-30 15:28:50

标签: javascript jquery html

我正在写一个网站,我想构建一些窗口大小的div /部分。当用户停止在其中两个div之间滚动时, div在此时需要更多空间应该滚动,因此它将是全窗口尺度的。

2 个答案:

答案 0 :(得分:1)

有jQuery插件可以执行此操作,但这里有一个很好的模板,可以看看如何实现自己的:

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

这是用于缓动函数的相关滚动JavaScript,使其更好并且可滚动:

//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();
    });
});

答案 1 :(得分:0)

FullPage.js完全符合您的需要。

如果整个库太重而无法满足您的需求,您可以尝试使用类似https://github.com/alvarotrigo/fullPage.js/blob/master/pure%20javascript%20(Alpha)/javascript.fullPage.js#L897-L913

之类的内容重新实现逻辑