0
我正在使用https://github.com/miguel-perez/smoothState.js並試圖使用上一頁的URL創建if/else語句。我嘗試將路徑名存儲在cookie中,但我也需要使用當前的路徑名,並且由於某種原因它僅記錄了cookie。使用SmoothState獲取/保留上一頁的URL
我希望這解釋了什麼是我想要做的事:
(function($) {
'use strict';
var $page = $('#main'),
options = {
debug: true,
prefetch: true,
cacheLength: 0,
onBefore: function($currentTarget, $container) {
// Keep the current page's pathname. Specifically
// check if it's the sites index
},
onStart: {
duration: 1000,
render: function ($container) {
$('#tempWrapper').remove();
// Check if the new page is the site's index or not
// and run a specific function
if (window.location.pathname == "/") {
smoothState.restartCSSAnimations();
} else {
$("html, body").animate({ scrollTop: "0px" });
$(".carousel").remove();
var $newContainer = $container.clone();
$newContainer.attr("id", "tempWrapper");
$newContainer.css({
position:'absolute',
top:$container.offset().top,
width:$container.css("width"),
maxHeight:"100vh",
overflow:"hidden"
});
// $container.empty();
$container.before($newContainer);
$('#inner-content').removeClass('entering');
var element = $('#inner-content', $newContainer);
setTimeout(callAnimation(element, true), 0);
}
}
},
onReady: {
duration: 1000,
render: function ($container, $newContent) {
$container.html($newContent);
// This is where it gets tricky: I need to check if
// the previous page was the site's index. If the
// previous page was a subpage, it does an animation.
if (window.location.pathname == "/") {
// Index (home) page
} else {
// Do animations
var element = document.getElementById($container[0].id).getElementsByClassName('move')[0];
callAnimation(element);
}
}
}
},
smoothState = $page.smoothState(options).data('smoothState');
})(jQuery);
我內聯我的筆記,任何幫助是極大的讚賞。我也嘗試使用document.referrer,但顯示空白;我假設這是因爲沒有點擊頁面刷新。