我正在使用Smoothstate.js向我的网站添加页面过渡,并尝试使用onStart、onProgress和onReady函数显示每个页面过渡之间的加载页面。
我的代码可以工作,但它会时不时地卡在加载页面上,并且容器div不会删除“is- loading”类。然而,它正在删除is - with类,即使它们使用相同的removeClass行?
我很困惑为什么它不能被移除。有谁能帮帮忙吗?
// Photoswipe
$(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) {
setTimeout(function() {
$container.addClass('is-loading');
$('#progressBar').append('<div id="bar"></div>');
var progress = '100%';
$('#bar').animate({
width: progress
}, 400);
}, 500);
}
},
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();
}
},
smoothState = $('#main').smoothState(options).data('smoothState');
});发布于 2018-02-07 21:08:24
给你个提示:
在加载过程开始后500ms,添加is-loading。那么,有没有可能在你的500ms超时之前onReady就被解雇了呢?因此,在removeClass调用之后,是否会再次将- your添加为类?
tl;dr:问题很可能是这里的超时
setTimeout(function() {
$container.addClass('is-loading');
$('#progressBar').append('<div id="bar"></div>');
var progress = '100%';
$('#bar').animate({
width: progress
}, 400);
}, 500);https://stackoverflow.com/questions/48663729
复制相似问题