Replace Velocity.js with Animate.css (#41)

* Drop Velocity.js

* Update docs
This commit is contained in:
Mimi 2020-07-03 10:44:18 +08:00 committed by GitHub
parent 659347cc1e
commit 6147217b44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 135 additions and 159 deletions

2
.gitignore vendored
View File

@ -12,4 +12,4 @@ source/lib/*
# Track internal libraries & Ignore unused verdors files # Track internal libraries & Ignore unused verdors files
!source/lib/font-awesome/ !source/lib/font-awesome/
!source/lib/anime.min.js !source/lib/anime.min.js
!source/lib/velocity/ !source/lib/animate-css/

View File

@ -814,25 +814,19 @@ mermaid:
# Animation Settings # Animation Settings
# --------------------------------------------------------------- # ---------------------------------------------------------------
# Use velocity to animate everything. # Use Animate.css to animate everything.
# For more information: http://velocityjs.org # For more information: https://animate.style
motion: motion:
enable: true enable: true
async: false async: false
transition: transition:
# Transition variants: # All available Transition variants: https://theme-next.js.org/animate/
# fadeIn | flipXIn | flipYIn | flipBounceXIn | flipBounceYIn
# swoopIn | whirlIn | shrinkIn | expandIn
# bounceIn | bounceUpIn | bounceDownIn | bounceLeftIn | bounceRightIn
# slideUpIn | slideDownIn | slideLeftIn | slideRightIn
# slideUpBigIn | slideDownBigIn | slideLeftBigIn | slideRightBigIn
# perspectiveUpIn | perspectiveDownIn | perspectiveLeftIn | perspectiveRightIn
post_block: fadeIn post_block: fadeIn
post_header: slideDownIn post_header: fadeInDown
post_body: slideDownIn post_body: fadeInDown
coll_header: slideLeftIn coll_header: fadeInLeft
# Only for Pisces | Gemini. # Only for Pisces | Gemini.
sidebar: slideUpIn sidebar: fadeInUp
# Progress bar in the top during page loading. # Progress bar in the top during page loading.
# For more information: https://github.com/HubSpot/pace # For more information: https://github.com/HubSpot/pace
@ -876,11 +870,13 @@ vendors:
internal: local internal: local
# Internal version: 3.1.0 # Internal version: 3.1.0
# anime: //cdn.jsdelivr.net/npm/animejs@3.1.0/lib/anime.min.js
# anime: //unpkg.com/animejs@3.1.0/lib/anime.min.js # anime: //unpkg.com/animejs@3.1.0/lib/anime.min.js
# anime: //cdnjs.cloudflare.com/ajax/libs/animejs/3.1.0/anime.min.js # anime: //cdnjs.cloudflare.com/ajax/libs/animejs/3.1.0/anime.min.js
anime: anime:
# Internal version: 5.13.0 # Internal version: 5.13.0
# fontawesome: //cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5/css/all.min.css
# fontawesome: //unpkg.com/@fortawesome/fontawesome-free@5/css/all.min.css # fontawesome: //unpkg.com/@fortawesome/fontawesome-free@5/css/all.min.css
# fontawesome: //cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css # fontawesome: //cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css
fontawesome: fontawesome:
@ -967,13 +963,11 @@ vendors:
# mermaid: //cdnjs.cloudflare.com/ajax/libs/mermaid/8.5.2/mermaid.min.js # mermaid: //cdnjs.cloudflare.com/ajax/libs/mermaid/8.5.2/mermaid.min.js
mermaid: mermaid:
# Internal version: 1.2.1 # Internal version: 3.1.1
# velocity: //unpkg.com/velocity-animate@1/velocity.min.js # animate_css: //cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css
# velocity: //cdnjs.cloudflare.com/ajax/libs/velocity/1.2.1/velocity.min.js # animate_css: //unpkg.com/animate.css@3.1.1/animate.min.css
# velocity_ui: //unpkg.com/velocity-animate@1/velocity.ui.min.js # animate_css: //cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css
# velocity_ui: //cdnjs.cloudflare.com/ajax/libs/velocity/1.2.1/velocity.ui.min.js animate_css:
velocity:
velocity_ui:
# Internal version: 1.0.2 # Internal version: 1.0.2
# pace: //unpkg.com/pace-js@1/pace.min.js # pace: //unpkg.com/pace-js@1/pace.min.js

View File

@ -25,7 +25,7 @@
<!--noindex--> <!--noindex-->
<section class="post-toc-wrap sidebar-panel"> <section class="post-toc-wrap sidebar-panel">
{%- if display_toc %} {%- if display_toc %}
<div class="post-toc motion-element">{{ toc }}</div> <div class="post-toc animated">{{ toc }}</div>
{%- endif %} {%- endif %}
</section> </section>
<!--/noindex--> <!--/noindex-->
@ -37,7 +37,7 @@
</section> </section>
{%- if theme.back2top.enable and theme.back2top.sidebar %} {%- if theme.back2top.enable and theme.back2top.sidebar %}
<div class="back-to-top motion-element"> <div class="back-to-top animated">
<i class="fa fa-arrow-up"></i> <i class="fa fa-arrow-up"></i>
<span>0%</span> <span>0%</span>
</div> </div>

View File

@ -46,6 +46,11 @@
{%- set font_awesome_uri = theme.vendors.fontawesome or url_for('lib/font-awesome/css/all.min.css') %} {%- set font_awesome_uri = theme.vendors.fontawesome or url_for('lib/font-awesome/css/all.min.css') %}
<link rel="stylesheet" href="{{ font_awesome_uri }}"> <link rel="stylesheet" href="{{ font_awesome_uri }}">
{%-if theme.motion.enable %}
{% set animate_css_uri = theme.vendors.animate_css or url_for('lib/animate-css/animate.min.css') %}
<link rel="stylesheet" href="{{ animate_css_uri }}">
{%- endif %}
{%- if theme.fancybox %} {%- if theme.fancybox %}
{%- set fancybox_css_uri = theme.vendors.fancybox_css or '//cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.css' %} {%- set fancybox_css_uri = theme.vendors.fancybox_css or '//cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.css' %}
<link rel="stylesheet" href="{{ fancybox_css_uri }}"> <link rel="stylesheet" href="{{ fancybox_css_uri }}">

View File

@ -1,4 +1,4 @@
<div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person"> <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
{%- if theme.avatar.url %} {%- if theme.avatar.url %}
<img class="site-author-image" itemprop="image" alt="{{ author }}" <img class="site-author-image" itemprop="image" alt="{{ author }}"
src="{{ url_for(theme.avatar.url) }}"> src="{{ url_for(theme.avatar.url) }}">
@ -8,7 +8,7 @@
</div> </div>
{%- if theme.site_state %} {%- if theme.site_state %}
<div class="site-state-wrap motion-element"> <div class="site-state-wrap animated">
<nav class="site-state"> <nav class="site-state">
{%- if config.archive_dir != '/' and site.posts.length > 0 %} {%- if config.archive_dir != '/' and site.posts.length > 0 %}
<div class="site-state-item site-state-posts"> <div class="site-state-item site-state-posts">
@ -61,7 +61,7 @@
{%- endif %} {%- endif %}
{%- if theme.chat.enable and theme.chat.service !== '' %} {%- if theme.chat.enable and theme.chat.service !== '' %}
<div class="sidebar-button motion-element"> <div class="sidebar-button animated">
{%- if theme.chat.service == 'chatra' and theme.chatra.enable %} {%- if theme.chat.service == 'chatra' and theme.chatra.enable %}
<a onclick="Chatra('openChat', true);"> <a onclick="Chatra('openChat', true);">
{%- endif %} {%- endif %}
@ -75,7 +75,7 @@
{%- endif %} {%- endif %}
{%- if theme.social %} {%- if theme.social %}
<div class="links-of-author motion-element"> <div class="links-of-author animated">
{%- for name, link in theme.social %} {%- for name, link in theme.social %}
<span class="links-of-author-item"> <span class="links-of-author-item">
{%- set sidebarURL = link.split('||')[0] | trim %} {%- set sidebarURL = link.split('||')[0] | trim %}
@ -96,7 +96,7 @@
{%- endif %} {%- endif %}
{%- if theme.creative_commons.license and theme.creative_commons.sidebar %} {%- if theme.creative_commons.license and theme.creative_commons.sidebar %}
<div class="cc-license motion-element" itemprop="license"> <div class="cc-license animated" itemprop="license">
{%- set ccImage = '<img src="' + url_for(theme.images + '/cc-' + theme.creative_commons.license + '.svg') + '" alt="Creative Commons">' %} {%- set ccImage = '<img src="' + url_for(theme.images + '/cc-' + theme.creative_commons.license + '.svg') + '" alt="Creative Commons">' %}
{{ next_url(ccURL, ccImage, {class: 'cc-opacity'}) }} {{ next_url(ccURL, ccImage, {class: 'cc-opacity'}) }}
</div> </div>
@ -104,7 +104,7 @@
{# Blogroll #} {# Blogroll #}
{%- if theme.links %} {%- if theme.links %}
<div class="links-of-blogroll motion-element"> <div class="links-of-blogroll animated">
<div class="links-of-blogroll-title"> <div class="links-of-blogroll-title">
{%- if theme.links_settings.icon %}<i class="{{ theme.links_settings.icon }} fa-fw"></i>{%- endif %} {%- if theme.links_settings.icon %}<i class="{{ theme.links_settings.icon }} fa-fw"></i>{%- endif %}
{{ theme.links_settings.title }} {{ theme.links_settings.title }}

View File

@ -2,8 +2,6 @@
<style> <style>
body { margin-top: 2rem; } body { margin-top: 2rem; }
.use-motion .header,
.use-motion .site-brand-container .toggle,
.use-motion .menu-item, .use-motion .menu-item,
.use-motion .sidebar, .use-motion .sidebar,
.use-motion .post-block, .use-motion .post-block,
@ -11,7 +9,12 @@
.use-motion .comments, .use-motion .comments,
.use-motion .post-header, .use-motion .post-header,
.use-motion .post-body, .use-motion .post-body,
.use-motion .collection-header, .use-motion .collection-header {
visibility: visible;
}
.use-motion .header,
.use-motion .site-brand-container .toggle,
.use-motion .footer { opacity: initial; } .use-motion .footer { opacity: initial; }
.use-motion .site-title, .use-motion .site-title,

View File

@ -7,7 +7,6 @@ hexo.extend.filter.register('after_generate', () => {
if (!theme.minify) return; if (!theme.minify) return;
const lists = hexo.route.list(); const lists = hexo.route.list();
const velocity = lists.filter(list => list.includes('lib/velocity'));
const fontawesome = lists.filter(list => list.includes('lib/font-awesome')); const fontawesome = lists.filter(list => list.includes('lib/font-awesome'));
if (!theme.bookmark.enable) { if (!theme.bookmark.enable) {
@ -16,15 +15,11 @@ hexo.extend.filter.register('after_generate', () => {
if (!theme.motion.enable) { if (!theme.motion.enable) {
hexo.route.remove('js/motion.js'); hexo.route.remove('js/motion.js');
velocity.forEach(path => { hexo.route.remove('lib/animate-css/animate.min.css');
hexo.route.remove(path);
});
} }
if (theme.motion.enable && theme.vendors.velocity && theme.vendors.velocity_ui) { if (theme.motion.enable && theme.vendors.animate_css) {
velocity.forEach(path => { hexo.route.remove('lib/animate-css/animate.min.css');
hexo.route.remove(path);
});
} }
if (theme.vendors.fontawesome) { if (theme.vendors.fontawesome) {

View File

@ -30,9 +30,5 @@ hexo.extend.helper.register('js_vendors', function() {
if (theme.pangu) { if (theme.pangu) {
vendors.pangu = '//cdn.jsdelivr.net/npm/pangu@4/dist/browser/pangu.min.js'; vendors.pangu = '//cdn.jsdelivr.net/npm/pangu@4/dist/browser/pangu.min.js';
} }
if (theme.motion.enable) {
vendors.velocity = 'lib/velocity/velocity.min.js';
vendors.velocity_ui = 'lib/velocity/velocity.ui.min.js';
}
return vendors; return vendors;
}); });

View File

@ -34,25 +34,25 @@
.use-motion { .use-motion {
if (hexo-config('motion.transition.post_block')) { if (hexo-config('motion.transition.post_block')) {
.post-block, .pagination, .comments { .post-block, .pagination, .comments {
opacity: 0; visibility: hidden;
} }
} }
if (hexo-config('motion.transition.post_header')) { if (hexo-config('motion.transition.post_header')) {
.post-header { .post-header {
opacity: 0; visibility: hidden;
} }
} }
if (hexo-config('motion.transition.post_body')) { if (hexo-config('motion.transition.post_body')) {
.post-body { .post-body {
opacity: 0; visibility: hidden;
} }
} }
if (hexo-config('motion.transition.coll_header')) { if (hexo-config('motion.transition.coll_header')) {
.collection-header { .collection-header {
opacity: 0; visibility: hidden;
} }
} }
} }

View File

@ -5,3 +5,7 @@
@import 'related-posts' if (hexo-config('related_posts.enable')); @import 'related-posts' if (hexo-config('related_posts.enable'));
@import 'math' if (hexo-config('math.mathjax.enable')); @import 'math' if (hexo-config('math.mathjax.enable'));
.use-motion .animated {
visibility: visible;
}

View File

@ -52,5 +52,5 @@
} }
.use-motion .menu-item { .use-motion .menu-item {
opacity: 0; visibility: hidden;
} }

View File

@ -13,7 +13,7 @@
} }
if (hexo-config('motion.enable') && hexo-config('motion.transition.sidebar')) { if (hexo-config('motion.enable') && hexo-config('motion.transition.sidebar')) {
opacity: 0; visibility: hidden;
} }
} }

View File

@ -1,49 +1,54 @@
/* global NexT, CONFIG, Velocity */ /* global NexT, CONFIG */
if (window.$ && window.$.Velocity) window.Velocity = window.$.Velocity;
NexT.motion = {}; NexT.motion = {};
NexT.motion.integrator = { NexT.motion.integrator = {
queue : [], queue: [],
cursor: -1,
init : function() { init : function() {
this.queue = []; this.queue = [];
this.cursor = -1;
return this; return this;
}, },
add: function(fn) { add: function(fn) {
this.queue.push(fn); const sequence = fn();
if (CONFIG.motion.async) this.queue.push(sequence);
else this.queue = this.queue.concat(sequence);
return this; return this;
}, },
next: function() {
this.cursor++;
const fn = this.queue[this.cursor];
typeof fn === 'function' && fn(NexT.motion.integrator);
},
bootstrap: function() { bootstrap: function() {
this.next(); if (!CONFIG.motion.async) this.queue = [this.queue];
this.queue.forEach(sequence => {
const timeline = window.anime.timeline({
duration: 200,
easing : 'linear'
});
sequence.forEach(item => {
if (item.deltaT) timeline.add(item, item.deltaT);
else timeline.add(item);
});
});
} }
}; };
NexT.motion.middleWares = { NexT.motion.middleWares = {
logo: function(integrator) { header: function() {
const sequence = []; const sequence = [];
function getMistLineSettings(targets) { function getMistLineSettings(targets) {
sequence.push([{ sequence.push({
targets, targets,
scaleX : [0, 1], scaleX : [0, 1],
duration: 500 duration: 500,
}, '-=200']); deltaT : '-=200'
});
} }
function pushToSequence(targets, sequenceQueue = false) { function pushToSequence(targets, sequenceQueue = false) {
sequence.push([{ sequence.push({
targets, targets,
opacity: 1, opacity: 1,
top : 0 top : 0,
}, sequenceQueue ? '-=200' : '-=0']); deltaT : sequenceQueue ? '-=200' : '-=0'
});
} }
pushToSequence('.header'); pushToSequence('.header');
@ -54,101 +59,67 @@ NexT.motion.middleWares = {
pushToSequence('.site-subtitle'); pushToSequence('.site-subtitle');
(CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini') && pushToSequence('.custom-logo-image'); (CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini') && pushToSequence('.custom-logo-image');
sequence[sequence.length - 1][0].complete = function() { document.querySelectorAll('.menu-item').forEach(targets => {
integrator.next(); sequence.push({
}; targets,
const timeline = window.anime.timeline({ begin : () => targets.classList.add('animated', 'fadeInDown'),
duration: 200, deltaT: '-=200'
easing : 'linear'
}); });
sequence.forEach(item => timeline.add(...item));
if (CONFIG.motion.async) {
integrator.next();
}
},
menu: function(integrator) {
Velocity(document.querySelectorAll('.menu-item'), 'transition.slideDownIn', {
display : null,
duration: 200,
complete: function() {
integrator.next();
}
}); });
if (CONFIG.motion.async || !document.querySelectorAll('.menu-item').length) { return sequence;
integrator.next();
}
}, },
subMenu: function(integrator) { subMenu: function() {
const subMenuItem = document.querySelectorAll('.sub-menu .menu-item'); const subMenuItem = document.querySelectorAll('.sub-menu .menu-item');
if (subMenuItem.length > 0) { if (subMenuItem.length > 0) {
subMenuItem.forEach(element => { subMenuItem.forEach(element => {
element.style.opacity = 1; element.classList.add('animated');
}); });
} }
integrator.next(); return [];
}, },
postList: function(integrator) { postList: function() {
const postBlock = document.querySelectorAll('.post-block, .pagination, .comments'); const sequence = [];
const postBlockTransition = CONFIG.motion.transition.post_block; const { post_block, post_header, post_body, coll_header } = CONFIG.motion.transition;
const postHeader = document.querySelectorAll('.post-header');
const postHeaderTransition = CONFIG.motion.transition.post_header;
const postBody = document.querySelectorAll('.post-body');
const postBodyTransition = CONFIG.motion.transition.post_body;
const collHeader = document.querySelectorAll('.collection-header');
const collHeaderTransition = CONFIG.motion.transition.coll_header;
if (postBlock.length > 0) { function animate(animation, selector) {
const postMotionOptions = window.postMotionOptions || { if (!animation) return;
stagger : 100, document.querySelectorAll(selector).forEach(targets => {
drag : true, sequence.push({
complete: function() { targets,
integrator.next(); begin : () => targets.classList.add('animated', animation),
deltaT: '-=100'
});
});
} }
};
if (postBlockTransition) { animate(post_block, '.post-block, .pagination, .comments');
Velocity(postBlock, 'transition.' + postBlockTransition, postMotionOptions); animate(coll_header, '.collection-header');
} animate(post_header, '.post-header');
if (postHeaderTransition) { animate(post_body, '.post-body');
Velocity(postHeader, 'transition.' + postHeaderTransition, postMotionOptions);
} return sequence;
if (postBodyTransition) {
Velocity(postBody, 'transition.' + postBodyTransition, postMotionOptions);
}
if (collHeaderTransition) {
Velocity(collHeader, 'transition.' + collHeaderTransition, postMotionOptions);
}
}
if (CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini') {
integrator.next();
}
}, },
sidebar: function(integrator) { sidebar: function() {
const sidebar = document.querySelector('.sidebar'); const sidebar = document.querySelector('.sidebar');
const sidebarTransition = CONFIG.motion.transition.sidebar; const sidebarTransition = CONFIG.motion.transition.sidebar;
// Only for Pisces | Gemini. // Only for Pisces | Gemini.
if (sidebarTransition && (CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini')) { if (sidebarTransition && (CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini')) {
Velocity(sidebar, 'transition.' + sidebarTransition, { return [{
display : null, targets: sidebar,
duration: 200 begin : () => sidebar.classList.add('animated', sidebarTransition)
}); }];
} }
integrator.next(); return [];
}, },
footer: function(integrator) { footer: function() {
const footer = document.querySelector('.footer'); return [{
Velocity(footer, { targets: document.querySelector('.footer'),
opacity: 1 opacity: 1
}, { }];
duration: 200
});
integrator.next();
} }
}; };

View File

@ -112,8 +112,7 @@ NexT.boot.motion = function() {
// Define Motion Sequence & Bootstrap Motion. // Define Motion Sequence & Bootstrap Motion.
if (CONFIG.motion.enable) { if (CONFIG.motion.enable) {
NexT.motion.integrator NexT.motion.integrator
.add(NexT.motion.middleWares.logo) .add(NexT.motion.middleWares.header)
.add(NexT.motion.middleWares.menu)
.add(NexT.motion.middleWares.postList) .add(NexT.motion.middleWares.postList)
.add(NexT.motion.middleWares.sidebar) .add(NexT.motion.middleWares.sidebar)
.add(NexT.motion.middleWares.footer) .add(NexT.motion.middleWares.footer)

View File

@ -1,4 +1,4 @@
/* global CONFIG, Velocity */ /* global CONFIG */
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
@ -33,12 +33,15 @@ document.addEventListener('DOMContentLoaded', () => {
}, },
showSidebar: function() { showSidebar: function() {
document.body.classList.add('sidebar-active'); document.body.classList.add('sidebar-active');
if (typeof Velocity === 'function') { const animateAction = isRight ? 'fadeInRight' : 'fadeInLeft';
Velocity(document.querySelectorAll('.sidebar .motion-element'), isRight ? 'transition.slideRightIn' : 'transition.slideLeftIn', { document.querySelectorAll('.sidebar .animated').forEach((element, index) => {
stagger: 50, element.style.animationDelay = (100 * index) + 'ms';
drag : true element.classList.remove(animateAction);
setTimeout(() => {
// Trigger a DOM reflow
element.classList.add(animateAction);
}, 0);
}); });
}
}, },
hideSidebar: function() { hideSidebar: function() {
document.body.classList.remove('sidebar-active'); document.body.classList.remove('sidebar-active');

12
source/lib/animate-css/animate.min.css vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long