1

我正在使用 Scrollify 插件。单击按钮时,我想移动到某个部分。但是当我设置sectionName为时false,它似乎不起作用。sectionName当未设置为时它工作正常false,但我不想在我的地址栏上看到 # 因为当我刷新/重新加载页面(例如在第 3 部分)并滚动时,它会滚动到下一部分(从第一节到第四节)。
有没有办法在什么时候移动到特定sectionName部分false

这是我到目前为止所做的:
JS

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

HTML

<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>

谢谢!:)

4

2 回答 2

0

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

$("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;
};

它工作得很好:)

于 2017-01-12T16:44:19.627 回答
0

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

于 2016-09-10T18:46:59.120 回答