当sectionName为false时,滚动移动不工作

Scrollify Move not working when sectionName is false

本文关键字:滚动 移动 工作 sectionName false      更新时间:2023-09-26

我正在使用Scrollify插件。我想在点击按钮时移动到某个区域。但是当我将sectionName设置为false时,它似乎不起作用。当sectionName未设置为false时,它可以正常工作,但我不想在我的地址栏上看到#,因为当我刷新/重新加载页面(例如在第3部分)并滚动时,它会立即滚动到下一节(从第1部分到第4部分)。
sectionNamefalse时,是否有办法将移动到到特定的部分?

以下是我目前所做的:
JS

$('.goNotify').click(function (e) {
    e.preventDefault();
    $.scrollify.move($(this).attr("href"));
});

<a href="#notify" class="goNotify">
    <button id="btnDrive" class="btnNotif" type="button" name="btnDrive" title="Get Notified When Available">Get Notified When Available</button>
</a>
<section id="notify" class="panel" data-section-name="notify">
<!-- content -->
</section>

谢谢!:)

您需要将要移动到的部分的索引传递给move方法。

当然,所以我有同样的问题,并通过这段代码绕过它:

$("a.scrollify").on("click",function() {
    $.scrollify.move( getScrollifySectionIndex( $(this).attr("href") ) );
});

«getScrollifySectionIndex»方法解析href并返回面板索引:

function getScrollifySectionIndex(anchor){
    var idpanel = false;
    jQuery('section.panel').each(function(i){
        if( jQuery(this).data('section-name') == anchor.toString().replace(/#/g,"") ){
        //console.log( jQuery(this).data('section-name') , i , anchor.toString().replace(/#/g,"") );
        idpanel = i;
        }
    });
    return idpanel;
};

效果很好:)