jQuery Page Transition Plugin smoothstate.js

Add-ons
2026-07-25 23:38 4 次浏览 • 0 次下载 0KB
jQuery Page Transition Plugin smoothstate.js

Usage

smoothState.js allows you to implement clean and seamless page transitions on your website. To achieve this effect, smoothState handles several tasks:

- Updates the URL using popState

- Fetches content from your server via AJAX

- Replaces the page content with the new content


Basic Method

To implement this functionality, you can run:

1
$('#body').smoothState();

This line of code allows the content of any internal link within the #body container to be updated without reloading the page.


Adding Page Transitions

In traditional animations, scene transitions require extracting a series of frames and displaying them rapidly in sequence. Similarly, smoothState allows you to define an array of functions that return the markup for the outgoing page. This is useful because it allows you to add the HTML structure required for CSS animations. Here is a basic example of a simple fade effect:

Javascript:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$('#body').smoothState({
renderFrame: [
// Frame 1: sets up scaffolding needed for CSS animations
function ($content, $container) {
var currentHTML = $container.html(),
newHTML = $('<div/>').append($content).html(),
html = [
'<div class=\'content\' style=\'height:' + $container.height() + 'px;\'>',
'<div class=\'page page--old\'>' + currentHTML + '</div>',
'<div class=\'page page--new\'>' + newHTML + '</div>',
'</div>'
].join('');
return html;
},
// Frame 2: cleans up extra markup added for CSS animations
function ($content) {
return $('<div/>').append($content).html();
}
]
});


CSS:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* Page transitions - simple fade effect
------------------------------------------------- */
#body .content {
position: relative;
z-index: 1;
}
#body .page {
position: absolute;
top: 0;
left: 0;
width: 100%;
}
#body .page--old {
animation: fadeOut 0.1s ease; /* Don't forget to add vendor prefixes! */
opacity: 0;
z-index: 1;
}
#body .page--new {
visibility: visible;
animation: fadeIn 0.4s ease;
z-index: 2;
}
/* Animations classes
------------------------------------------------- */
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes fadeOut {
from {
opacity: 1;
}
to {
opacity: 2;
}
}

You can view this simple demo and apply it to your own website.

星河码客

发现和分享优质开源项目,传承互联网精神,为开发者服务。

关于本站

联系我们

微信/广告合作:ITcloub (备注星河码客)

免责声明:本站资源版权归原作者所有,仅供学习与交流。如有侵权,请通过「关于我们 - 侵权投诉」联系删除。

Powered by Nuxt · Deployed on Cloudflare