- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用插件 smoothstate.js在我的网站上。出于某种原因,当我使用后退和前进按钮浏览页面时,后退按钮有时会停止工作。
URL 变了,但内容保持不变?
我已经检查了控制台显示的错误:
TypeError: Cannot read property 'state' of undefined
有人知道为什么会这样吗?就像我说的,大多数时候它工作正常,但突然就不行了。
我使用的代码是这样的:
$(function(){
'use strict';
var options = {
prefetch: true,
debug:true,
cacheLength: 0,
repeatDelay: 500,
onStart: {
duration: 0, // Duration of our animation
render: function ($container) {
// Add your CSS animation reversing class
$container.addClass('is-exiting');
// Restart your animation
smoothState.restartCSSAnimations();
}
},
onProgress: {
// How long this animation takes
duration: 0,
// A function that dictates the animations that take place
render: function ($container) {
$container.addClass('is-loading');
$('#progressBar').append('<div id="bar"></div>');
var progress = '100%';
$('#bar').animate({
width: progress
}, 400);
}
},
onReady: {
duration: 0,
render: function ($container, $newContent) {
$container.removeClass('is-loading is-exiting');
// Inject the new content
$container.html($newContent);
},
},
onAfter: function() {
navbarAnimate();
closeMenu();
ImageSliders();
initPhotoSwipeFromDOM('.gallery');
ImageOverlay();
window.parsePinBtns();
backToTop();
}
},
smoothState = $('#main').smoothState(options).data('smoothState');
});
最佳答案
我也遇到了这个问题,当页面没有完全加载的情况下点击后退和前进按钮的速度太快时就会发生这种情况。如果 page.cache[page.href] 未定义,我的一个 hacky 解决方案是重新加载页面。
/** Handles the popstate event, like when the user hits 'back' */
onPopState = function(e) {
if(e.state !== null || typeof e.state !== undefined) {
var url = window.location.href;
var $page = $('#' + e.state.id);
var page = $page.data('smoothState');
if (typeof(page.cache[page.href]) !== 'undefined') {
var diffUrl = (page.href !== url && !utility.isHash(url, page.href));
var diffState = (e.state !== page.cache[page.href].state);
if(diffUrl || diffState) {
if (diffState) {
page.clear(page.href);
}
page.load(url, false);
}
}
else {
//reload the page if page.cache[page.href] is undefined
location.reload();
}
}
},
关于javascript - smoothstate.js - 后退按钮有时不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49005788/
我的网站在每个页面上都使用 smoothstate.js。在几页上,我弹出一个带有表单的模式框。这些表格工作得很好。 在另一个页面上,我有一个包含在 html 中的基本表单。当我单击表单上的提交按钮时
我目前正在尝试在我的网站上实现 smoothState.js。然而,我在页面之间转换时遇到了问题。 问题在于新内容是“无样式的”(更准确地说,它的样式与上一页的样式相同)。由于我非常关注此网站的性能,
我正在一个网站上工作,我决定将 smoothstate.js 插入其中。我已经按照有关如何安装它的指南进行操作并且能够安装它,但是我只有一个问题。加载页面时会执行介绍动画,但是当我单击链接并加载另一个
我正在使用插件 smoothstate.js在我的网站上。出于某种原因,当我使用后退和前进按钮浏览页面时,后退按钮有时会停止工作。 URL 变了,但内容保持不变? 我已经检查了控制台显示的错误: Ty
我的网站在大多数页面上都有类似 slider 的元素。我正在尝试实现 SmoothState JS,但遇到了第二页中断的问题。通过文档我知道我可能需要添加 onAfter 回调,但我想知道在哪里以及如
我已经成功实现了 smoothState.js我的网站上有一个插件,它工作得很好,但我的另一个非常简单的 jQuery 插件将无法工作,其开头为: $(document).ready() 我需要刷新页
在 smoothstate.js 库中场景元素的反向动画有一些问题。我在网站上工作:LINK 实际上“.is-exiting”类适用于 DOM 但动画没有发生这是我的 CSS: .animated .
当单击链接 smoothstate 加载新页面的内容时,我想用新页面上可见的类来标识引用页面。有什么办法可以做到这一点吗? 最佳答案 这不是最动态的解决方案,但我最终所做的是将类设置为引用页面上的 a
我尝试嵌入 smoothState.js进入我的元素。但是出于任何原因,“动画方向:交替反转;”不工作(或其他)。该元素只是淡入而不是淡出。我尝试了一切,但没有任何效果。 html archiv
我正在使用 smoothstate.js 进行页面转换,但每当我单击转到另一个页面的链接时,我都无法尝试让动画退出。自动画正常启动以来,页面加载时我没有问题。仅退出时页面将正常退出,没有任何过渡或动画
我正在努力创建从介绍页面到主页的平滑过渡,您可以在此处看到 http://trial.kareemhackett.com所以我使用了 smoothstate.js 但我无法让它在页面之间平滑过渡,我觉
我尝试将 smoothState.js 嵌入到我的元素中,但出于任何原因,reverse/toogle/exiting 动画无法正常工作。我真的没有更多的想法,我找不到关于 stackoverflow
当所有内容完全加载时,我需要页面加载器到每个页面。 我需要什么: $(window).load(function(){ $('#loading').fadeOut(); }); 当 Smooth
我正在使用 Smoothstate.js 向我的网站添加页面转换,并尝试使用 onStart、onProgress 和 onReady 函数在每个页面转换之间显示一个加载页面。 我的代码有效,但它时不
我正在使用 SmoothState.js 进行页面转换,它工作正常并使用 ajax 加载新页面。但是,我在每个需要重新初始化的页面上都有 JS 脚本,但我无法让它们始终出现在页面转换中。 Based
我正在构建一个简单的网站,我想使用来自 SmoothState.js 的漂亮转换,但我也使用了其他 jQuery 脚本(例如 Flexslider ),我已将其设置为在 $(document).rea
我知道这个问题在很多地方都被问过,但我还没有找到适合我的情况的答案。 我使用 smoothstate.js 在页面加载时触发一系列动画,并(希望)在页面退出时反转动画。 在页面加载时效果很好,但在反转
我正在尝试使 smoothState.js 插件正常工作。单击从 index.html 到 secondary.html 的链接后,动画会产生相反的效果但不会导致 secondary.html,实际上
我在“header.php”页面的代码中使用带有简码的 Wordpress 音频播放器。 我也在使用 SmoothState ( http://miguel-perez.github.io/smoot
我正在尝试使用 Masonry和 smoothState在页面之间使用 SmoothState 动画一起使用。 下面的代码使 smoothState 动画可以向前和向后工作: $(function()
我是一名优秀的程序员,十分优秀!