我正在使用 SmoothState.Js 在点击时加载新页面。由于在每一页上, Logo 都保持在相同的位置/大小,因此我希望 Logo 不会刷新,也不会在页面更改时淡出/淡出。
我的菜单中的链接不会刷新,但 Logo 会刷新。我没有在文档或 Google 上看到任何解决这个问题的内容。我如何在这些 ajax 页面更改之间始终保持图像就位?
这是 SmoothState 调用:
$(function() {
$('#main').smoothState();
});
$(function() {
"use strict";
var options = {
prefetch: true,
pageCacheSize: 4,
onStart: {
duration: 300, // 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 = $("#main").smoothState(options).data("smoothState");
});
HTML:
<header class="header">
<div class="main-logo">
<a class="svg" href="www.site.com">
<object class="willItBlend" data="../svg/main-logo.svg" type="image/svg+xml"></object>
<img class="blender" src="../svg/main-logo.png" />
</a>
</div>
<nav class="main-nav-about">
// links go here
</nav>
</header>
SmoothState 的可用事件调用:
onBefore - Runs before a page load has been started
onStart - Runs once a page load has been activated
onProgress - Runs if the page request is still pending and the onStart animations have finished
onReady - Run once the requested content is ready to be injected into the page and the previous animations have finished
onAfter - Runs after the new content has been injected into the page and all animations are complete
最佳答案
您需要使用文档中指定的“黑名单”选项:
A jQuery selector specifying which elements within the smoothState element should be ignored. This includes both form and anchor elements.
只需将其添加到选项对象blacklist: '.no-smoothState'
然后将 .no-smoothState
类添加到您想要忽略的任何页面元素。
关于javascript - SmoothStateJS : how to keep an element from refreshing on page change?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35662260/