当 sectionName 为 false 时,Scrollify Move 不起作用
Scrollify Move not working when sectionName is false
我正在使用 Scrollify 插件。我想在单击按钮时移动到某个部分。但是当我把sectionName
设置成false
的时候,好像就不行了。当 sectionName
未设置为 false
时它工作正常,但我不想在我的地址栏上看到 # 因为当我 refresh/reload 页面(例如在第 3 部分) 并滚动,它会滚动到下一部分(从第 1 部分到第 4 部分)。
当 sectionName
是 false
时,有没有办法 MOVE 到特定部分?
这是我目前所做的:
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>
谢谢! :)
您需要将要移动到的部分的索引传递给移动方法。
当然,所以我遇到了同样的问题,并通过这段代码绕过它:
$("a.scrollify").on("click",function() {
$.scrollify.move( getScrollifySectionIndex( $(this).attr("href") ) );
});
« getScrollifySectionIndex » 方法解析 href 和 return 面板索引 :
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;
};
效果很好:)
我正在使用 Scrollify 插件。我想在单击按钮时移动到某个部分。但是当我把sectionName
设置成false
的时候,好像就不行了。当 sectionName
未设置为 false
时它工作正常,但我不想在我的地址栏上看到 # 因为当我 refresh/reload 页面(例如在第 3 部分) 并滚动,它会滚动到下一部分(从第 1 部分到第 4 部分)。
当 sectionName
是 false
时,有没有办法 MOVE 到特定部分?
这是我目前所做的:
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>
谢谢! :)
您需要将要移动到的部分的索引传递给移动方法。
当然,所以我遇到了同样的问题,并通过这段代码绕过它:
$("a.scrollify").on("click",function() {
$.scrollify.move( getScrollifySectionIndex( $(this).attr("href") ) );
});
« getScrollifySectionIndex » 方法解析 href 和 return 面板索引 :
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;
};
效果很好:)