我們在我們的應用程序中轉換了一個頁面,該頁面先前將來自各個頁面的內容轉換爲使用Javascript平滑滾動到每個部分的單個頁面。平滑滾動不能在Rails中工作,除非頁面被刷新
除非刷新頁面,否則此功能不起作用。我相信它與turbolinks緩存頁面有關。
過渡cacheing在整個
Turbolinks.enableTransitionCache()
平滑滾動功能
$(function() {
$('.scroll-button').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top - 160
}, 1000);
return false;
}
}
});
});
我試着選擇退出以各種方式turbolinks和過渡cacheing的啓用,最近標記每個環節,頁面容器和目標部分data-no-turbolink="true"
example_links.html.slim
中的每個鏈接已被標記爲 李 =的link_to 'INFO',路徑,類: '標籤鏈路滾動按鈕', '數據沒有的TurboLink'=> '真'
的show.html.slim
具有頁容器標籤
.row data-no-transition-cache="true" data-no-turbolink="true"
而且每個目標在該網頁部分進行標記
p.section-heading#someLabel data-no-turbolink="true"
我如何能確保網頁時,通過單擊鏈接或使用返回按鈕,使平滑滾動功能是強制執行訪問?