gpt4 book ai didi

javascript - 如何将加载器添加到 SmoothState.Js 页面更改

转载 作者:行者123 更新时间:2023-12-02 14:16:16 25 4
gpt4 key购买 nike

当所有内容完全加载时,我需要页面加载器到每个页面。

我需要什么:

$(window).load(function(){
$('#loading').fadeOut();
});

SmoothState.Js 更改时,有什么解决方案可以在每个页面上使用这个简单的功能吗?

这是我尝试过但不起作用的方法:

onAfter: function($container, $newContent){
$(window).load(function(){
$('#loading').fadeOut();
});
}

最佳答案

我有一个类似的问题,并花了相当长的时间寻找解决方案。最终,我决定自己想出一个解决方案,但我没有使用 JS 将其附加到 SmoothState 本身,而是使用了 CSS 解决方案。我希望这可以帮助您以及可能有相同需求的其他人。

我的 SmoothState 配置如下:

jQuery(function(){
'use strict';
var $page = jQuery('#smoothStateMain'),
options = {
debug: true,
anchors: 'a',
blacklist: 'no-ajax',
prefetch: true,
prefetchOn: 'mouseover touchstart',
cacheLength: 5,
forms: 'form',
onStart: {
duration: 50, // Duration of our animation
render: function ($container) {
// Add your CSS animation reversing class
$container.addClass('is-exiting');
// Restart your animation
smoothState.restartCSSAnimations();
}
},
onReady: {
duration: 0,
render: function ($container, $newContent) {
// Remove your CSS animation reversing class
$container.removeClass('is-exiting');
// Inject the new content
$container.html($newContent);
}
}
},
smoothState = $page.smoothState(options).data('smoothState');

});

这显然是一个相当正常的 SmoothState 配置,它在页面转换时将“is-exiting”添加到 m 场景类容器。

这是我的 HTML:

<body id="body">
<div id="smoothStateMain" class="m-scene">
<div class="loading"></div>
<!-- Start body_class again for smoothState reload -->
<div <?php body_class(''); ?>>

为了显示和隐藏加载图标,我有以下 CSS:

@keyframes loading{
0%{transform:rotate(0deg)}
100%{transform:rotate(360deg)}
}

@-webkit-keyframes loading{
0%{-webkit-transform:rotate(0deg)}
100%{-webkit-transform:rotate(360deg)}
}

.m-scene.is-exiting .loading {
/* Show loader when there's no page transition */
display: block
}

.m-scene .loading {
/* Hide loader when there's no page transition */
display: none;
}

.loading {
/* Your loader style here */
animation-duration: .5s;

/* Some general styling */
width: 30px;
height: 30px;
border-radius: 150px;
border: 2px solid #000;
border-top-color: rgba(0, 0, 0, 0.3);
box-sizing: border-box;
position: absolute;
top: 10%;
right: 10%;
animation: loading 1s linear infinite;
-webkit-animation: loading 1s linear infinite;

/* To show the loader over any other elements */
z-index: 9999;
}

请原谅我有任何不良的 StackOverflow 习惯,这是我的第一篇文章。 CSS 动画允许更多的功能。例如,您可能希望将加载程序的显示延迟几毫秒,以防止它在您的网站即时加载页面时显示(这样它就不会闪烁或在很短的时间内显示)。

祝你好运!

关于javascript - 如何将加载器添加到 SmoothState.Js 页面更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39000937/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com