[英]classlist.remove when going back in history
I made a small page-transition with javascript.我用javascript做了一个小的页面转换。
When the user clicks a link, a black div gets the class "slide" which triggers the animation going on opacity from 0 to 1.当用户点击一个链接时,一个黑色的 div 会获得“slide”类,它会触发动画从 0 到 1 的不透明度。
Then, it triggers the link to the next page, where a black div animates from opacity 1 to 0. This works just fine.然后,它触发到下一页的链接,其中黑色 div 从不透明度 1 变为 0。这工作得很好。
But when I go back in history the div still has the class "slide", so that I only see a black rectangle.但是当我回顾历史时,div 仍然有“幻灯片”类,所以我只看到一个黑色矩形。
When I put a classList.remove("slide")
in the setTimeout
this problem is gone but I see the page for a millisecond when switching to the other page.当我在
setTimeout
中放置一个classList.remove("slide")
时,这个问题就消失了,但是当我切换到另一个页面时,我看到该页面有一毫秒。
Does anyone have an idea how I can solve this issue?有谁知道我该如何解决这个问题?
for (let i = 0; i < link.length; i++) {
link[i].addEventListener("click", (e) => {
e.preventDefault();
transition.classList.add("slide");
setTimeout(() => {
window.location = link[i].href;
}, 450);
});
}
The solution: performance.navigation.type as mentioned in the second answer here: How to force reloading a page when using browser back button?解决方案:performance.navigation.type 如第二个答案中所述: How to force reloading a page when using browser back button?
if(performance.navigation.type == 2){
location.reload(true);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.