一个简单易于使用的动画库,用于Web开发人员
git页·操场演示·报告错误·请求功能
JOS-Animation,Scroll Animation库上的JavaScript是一个简单易用的动画库软件包,可以立即将专业动画添加到您的网站上。它的构建是为了使我的生活更轻松,并带有大量功能,并且可以完全自定义。它是轻巧的,足迹很小。最好的部分是它没有(*最低)性能损失。
该项目目前是由ME&The Dev社区开发的,因此您可以期待更多的功能和更新。
受到AOS库GSAP的启发。我想要一些更容易使用的东西,性能出色,并希望使实施更好。因此,我从头开始从事这个项目。
请随时报告问题或请求此存储库中的功能:)&有关更多信息,请查看JOS网页。
< a
target =" _blank "
rel =" noopener noreferrer nofollow "
href =" https://github.com/jesvijonathan/JOS-Animation-Library "
>
< img
src =" https://cdn.jsdelivr.net/gh/jesvijonathan/JOS-Animation-Library@master/res/badge/jos_github%20default.svg "
alt =" JOS-Animation "
style =" max-width: 100%; "
/> </ a > JOS v0.9.2 11 Nov 2023 Jesvi Jonathan
您可以选择从各种来源使用最新版本的JO:
< script
src =" https://cdnjs.cloudflare.com/ajax/libs/jos-animation/0.9.2/jos.js "
integrity =" sha512-ZbNmgrMmWwQspNz6WQ1HnqLEPMXE4PyJBVnuc10e4gwJhrycze2IzjDQPx4CxkOBnUyt5wNCekdeTRJOe8J4WA== "
crossorigin =" anonymous "
referrerpolicy =" no-referrer "
> </ script > < script src =" https://cdn.jsdelivr.net/npm/[email protected]/dist/jos.js " > </ script > < script src =" https://cdn.jsdelivr.net/gh/jesvijonathan/JOS-Animation-Library/dist/jos.js " > </ script >(或者)
< script src =" https://cdn.jsdelivr.net/npm/jos-animation/dist/jos.js " > </ script >(或者)
< script src =" https://cdn.jsdelivr.net/gh/jesvijonathan/JOS-Animation-Library/dist/v0.9.2/jos.js " > </ script > < script src =" https://unpkg.com/jos-animation " > </ script >(或者)
< script src =" https://unpkg.com/[email protected]/dist/jos.js " > </ script > < script src =" https://raw.githubusercontent.com/jesvijonathan/JOS-Animation-Library/master/dist/jos.js " > </ script >您可以在上面的脚本标签中用jos.min.js替换jos.js来添加脚本的缩小版本。
jos.js的基本。 jos.min.js生产使用。 jos.debug.js用于调试以及从v0.9开始的一些其他功能,默认情况下, jos.js不需要您添加stylesheet jos.css ,它将与脚本一起导出。但是,如果您想出于某种原因,您仍然可以添加样式表。 ###导入JOS1。使用NPM安装JOS(YARN或PNPM): jos-animation@latest[email protected][email protected]因此,最新版本的是https://unpkg.com/jos-animation/@latest/dist/jos.js (嵌入)。或jos-animation/@0.8.8/dist/jos.js (npm安装),用于特定版本。
npm install jos-animation // import "jos-animation/dist/jos.css";
// Above is required only for v0.8.8 & below (or) if you want to overide jos by using style from the stylesheet
import JOS from "jos-animation" ;
// Other ways to import JOS
// import JOS from "jos-animation/dist/jos.js";
// import JOS from "jos-animation/dist/jos.min.js";
// import JOS from "jos-animation/dist/jos.debug.js"; // main.js
import { createApp } from "vue" ;
import { watch , nextTick } from "vue" ;
import JOS from "jos-animation" ; // jos-animation/dist/jos.debug.js
import App from "./App.vue" ;
const app = createApp ( App ) ;
app . mount ( "#app" ) ;
JOS . init ( ) ;
//JOS.version();
watch (
( ) => router . currentRoute . value ,
( ) => {
nextTick ( ( ) => {
JOS . refresh ( ) ;
} ) ;
}
) ;
// To observe elements after a route change在:https://jos-animation.vercel.app/中使用
上面的vue.js示例也适用于nuxt.js
// index.js
import JOS from "jos-animation/dist/jos.js" ;
onload = ( ) => {
const options = {
debugMode : true ,
animation : "flip" ,
duration : 0.7 ,
rootMargin : "0% 0% 0% 0%" ,
} ;
JOS . init ( options ) ;
//JOS.version();
} ;
function Main ( ) {
useEffect ( ( ) => {
JOS . refresh ( ) ;
} , [ ] ) ;
// To observe elements after a route change
return (
< React . StrictMode >
< App />
</ React . StrictMode >
) ;
}
ReactDOM . createRoot ( document . getElementById ( "root" ) ) . render ( < Main /> ) ;在:https://azzle.netlify.app中使用
以上示例适用于react.js也适用于next.js&preact.js
// app/layout.tsx
import jos from "jos-animation/dist/jos.js" ;
export default function RootLayout ( {
children ,
} : {
children : React . ReactNode ;
} ) {
const jos_options = {
debugMode : false ,
passive : true ,
animation : "fade" ,
duration : 0.4 ,
rootMargin : "20% 0% 30% 0%" ,
} ;
useEffect ( ( ) => {
jos . init ( jos_options ) ;
} , [ ] ) ; // Once
useEffect ( ( ) => {
jos . refresh ( ) ;
} ) ; // For every update
return ( ) ;
}
// To observe elements after a route change在:https://bitspace-nextjs-jos.vercel.app中使用
import { Component , OnInit , AfterViewChecked } from '@angular/core' ;
import JOS from 'jos-animation' ;
@ Component ( {
selector : 'app-root' ,
templateUrl : './app.component.html' ,
styleUrls : [ './app.component.css' ]
} )
export class AppComponent implements OnInit , AfterViewChecked {
ngOnInit ( ) : void {
JOS . init ( ) ; // Once
}
ngAfterViewChecked ( ) : void {
JOS . refresh ( ) ; // For every update
}
// ... rest of your code
}您可以检查此讨论线程以获取更多信息:JOS for Angular
JOS.init();使用默认设置初始化库。 <!-- Initialize JOS with default settings -->
< script >
JOS . init ( ) ;
</ script >JOS.init(options);使用自定义设置过度默认设置。 <!-- Global Parameters -->
< script >
JOS . init ( {
// disable: false, // Disable JOS globally | Values : 'true', 'false'
debugMode : true , // Enable JOS debug mode | Values : 'true', 'false'
passive : false , // Set the passive option for the scroll event listener | Values : 'true', 'false'
once : false , // Disable JOS after first animation | Values : 'true', 'false' || Int : 0-1000
animation : "fade" , // JOS global animation type | Values : 'fade', 'slide', 'zoom', 'flip', 'fade-right', 'fade-left', 'fade-up', 'fade-down', 'zoom-in-right', 'zoom-in-left', 'zoom-in-up', 'zoom-in-down', 'zoom-out-right', 'zoom-out-left', 'zoom-out-up', 'zoom-out-down', 'flip-right', 'flip-left', 'flip-up', 'flip-down, spin, revolve, stretch, "my-custom-animation"
// animationInverse: "static", // Set the animation type for the element when it is scrolled out of view | Values : 'fade', 'slide', 'zoom', 'flip', 'fade-right', 'fade-left', 'fade-up', 'fade-down', 'zoom-in-right', 'zoom-in-left', 'zoom-in-up', 'zoom-in-down', 'zoom-out-right', 'zoom-out-left', 'zoom-out-up', 'zoom-out-down', 'flip-right', 'flip-left', 'flip-up', 'flip-down, spin, revolve, stretch, "my-custom-animation"
timingFunction : "ease-in-out" , // JOS global timing function | Values : 'ease', 'ease-in', 'ease-out', 'ease-in-out', 'linear', 'step-start', 'step-end', 'steps()', 'cubic-bezier()', 'my-custom-timing-function'
//mirror : false, // Set whether the element should animate back when scrolled out of view | Values : 'true', 'false'
threshold : 0 , // Set global the threshold for the element to be visible | Values : 0-1
delay : 0 , // Set global the delay for the animation to start | Values : 0,1,2,3,4,5
duration : 0.7 , // Set global the duration for the animation playback | Values : flota : 0-1 & int : 0,1,2,3,4,5
// startVisible: "true", // Set whether the element should animate when the page is loaded | Values : 'true', 'false' || MS : 0-10000
// scrollDirection: "down", // Set the scroll direction for the element to be visible | Values : 'up', 'down', 'none'
//scrollProgressDisable: true // disable or enable scroll callback function | Values : 'true', 'false'
// intersectionRatio: 0.4, // Set the intersection ratio between which the element should be visible | Values : 0-1 (automatically set)
// rootMargin_top: "0%", // Set by which percent the element should animate out (Recommended value between 10% to -30%)
// rootMargin_bottom: "-50%", // Set by which percent the element should animate out (Recommended value between -10% to -60%)
// rootMargin: "0% 0% -50% 0%", // Set the root margin for the element to be visible | Values : _% _% _% _% (automatically set)
} ) ;
</ script >class="jos"设置为您要动画的元素: <!-- JOS class is required to animate the element -->
< div class =" jos " > </ div >data-jos *属性以自定义要动画的元素, <!-- JOS attributes are optional and will work without them (class="jos" is mandatory). these attributes can be used to customize the animation of the element -->
< div
class =" jos "
data-jos_animation =" zoom "
data-jos_once =" false "
data-jos_duration =" 0.4 "
data-jos_delay =" 0.1 "
data-jos_timing-function =" ease-in-out "
data-jos_mirror =" true "
data-jos_rootMargin =" 0% 0% -50% 0% "
data-jos_rootMargin_top =" -10% "
data-jos_rootMargin_bottom =" -50% "
data-jos_scrollDirection =" down "
data-jos_startVisible =" false "
data-jos_threshold =" 0.4 "
data-jos_passive =" false "
data-jos_invoke =" myCustomFunction "
data-jos_invoke_out =" myCustomFunction_onExit "
data-jos_scroll =" your_callbackFunction "
data-jos_anchor =" #elementID "
> </ div >有关动画,属性和选项的完整信息,请参见JOS道具。
/* Custom animation class name starts with 'jos-' keyword followed by the animation name*/
. jos-my-custom-animation {
/* Set the initial state of the element */
}data-jos_animation属性设置为my-custom-animation来使用自定义动画: < div class =" jos " data-jos_animation =" my-custom-animation " > </ div >示例:自定义动画
/* Custom inverse animation class name starts with 'jos-' keyword followed by the animation name*/
. jos-my-custom-animation-inverse {
/* Set the initial state of the element */
}data-jos_animationInverse属性设置为my-custom-animation-inverse来使用自定义逆动画: < div class =" jos " data-jos_animationInverse =" my-custom-animation-inverse " > </ div >当您想从rootmargin滚动时,您想对元素进行动画作用时,这一点特别有用,这为精美的动画提供了更多的自定义性。
您还可以将data-jos_animation (“无”,“静态”,no-transition等)和data-jos_animationInverse属性的组合使用来创建自定义动画。
示例:自定义逆动画
/* Custom playable animation class name starts with 'jos-' keyword followed by the animation name*/
/* My Custom Playable Animation */
. jos-my-custom-animation {
transition : 1 s ;
animation : jos-my-custom-animation 1 s ease-in-out infinite;
transform : translateX ( 100 px );
}
/* Add Keyframes */
@keyframes jos-my-custom-animation {
0 % {
opacity : 1 ;
}
50 % {
transform : translateX ( -100 px );
}
}data-jos_animation属性设置为my-custom-animation & data-jos_animationInverse my-custom-animation-play来使用可播放的动画: < div
class =" jos "
data-jos_animation =" my-custom-animation "
data-jos_animationinverse =" static "
> </ div >在这里, data-jos_animationinverse属性设置为static ,以防止元素无法视图并保持最终状态。可播放的动画是触发的,并在将元素滚动到视图中时开始播放。
示例:可玩动画
/* Custom timing function attribute name starts with 'data-jos_timing_function' keyword & a custom name of your choice */
[ data-jos_timing_function = "myCustom-timingFunc" ] {
/* Set the timing of the element */
transition-timing-function : cubic-bezier ( 0.2 , 0.5 , 0.2 , 0.5 ) !important ;
}data-jos_timing-function属性设置为my-custom-timing-function : < div class =" jos " data-jos_timing-function =" myCustom-timingFunc " > </ div >示例:自定时功能
id : <!-- My reference anchor element -->
< div id =" myElement " > </ div >data-jos_anchor属性添加到它,ID以后缀#开始: <!-- My animated element -->
< div class =" jos " data-jos_anchor =" #myElement " > </ div >当将myElement元素滚动到视图中时,这会触发动画。
此功能很有用,尤其是当您想对处于固定位置的元素进行动画动画。
示例:锚
data-jos_scrollDirection属性添加到它: <!-- My animated element -->
< div class =" jos " data-jos_scrollDirection =" down " > </ div >当将元素从上到down方向滚动到视图中时,这会触发动画。
&您可以做同样的up 。
当您想从特定方向将其滚动到视图时,这一点特别有用。
示例:基于方向的动画
data-jos_startVisible属性添加到它: <!-- My animated element -->
< div class =" jos " data-jos_startVisible =" true " > </ div >加载页面时,这将设置要可见的元素。您可以通过在ms中设置值来添加延迟:
<!-- My animated element that is visible with a given timer/delay in ms-->
< div class =" jos " data-jos_startVisible =" 3000 " > </ div >这将在3000毫秒后加载页面时或如果值为0 (或)为true (或)时,将其设置为可见的元素。
此功能很有用,尤其是当您想要一个处于固定位置的元素时,或者存在着陆页中的元素最初处于无动画状态时处于可见状态。
示例:开始可见
// Create a custom function
function myCustomFunction ( ) {
// Do something
}data-jos_invoke属性设置为myCustomFunction :使用您的自定义功能: < div class =" jos " data-jos_invoke =" myCustomFunction " > </ div >当将元素滚动到视图中时,这会触发mycustomfunction()函数。
您可以使用data-jos_invoke_out属性来触发该元素的视图。
示例:自定义功能
data-jos_scroll属性添加到它: < div id =" elem1 " class =" jos " data-jos_scroll =" your_callbackFunction " >
Scroll Trigger Element
</ div > your_callbackFunction = ( element ) => {
// windowScrollProgress : element scroll pixel
console . log ( element . id , element . jos . windowScrollProgress ) ;
// scrollProgress : 0-1
element . style . opacity = element . jos . scrollProgress ;
// rootScrollProgress : +-0 to +-1
element . style . innerHTML = element . jos . rootScrollProgress ;
} ;这将触发your_callbackfunction()函数滚动时。这样,您可以处理元素的滚动进度。
示例:自定义功能
data-jos_stagger属性与jos类一起添加到它: < div
class =" jos parent_elem "
id =" stagger "
data-jos_stagger =" spin "
data-jos_staggerinverse =" none "
data-jos_stagger_anchor =" #elementID "
data-jos_stagger_sequence =" 0.1 "
data-jos_stagger_delay =" 0 "
data-jos_stagger_duration =" 0.4 "
data-jos_stagger_timing-function =" ease-in-out "
data-jos_stagger_mirror =" true "
data-jos_stagger_rootMargin =" 0% 0% -50% 0% "
data-jos_stagger_invoke =" myCustomFunction "
data-jos_stagger_invoke_out =" myCustomFunction_onExit "
data-jos_stagger_scroll =" your_callbackFunction "
data-jos_stagger_startVisible =" false "
data-jos_stagger_scrollDirection =" down "
data-jos_stagger_once =" false "
>
<!-- data-jos_stagger="true" # this attribute along with 'jos' class in parent element is Required/Must to enable staggering -->
<!-- data-jos_stagger_anchor="true" # auto sets parent element's id & uses it as a anchor's -->
<!-- Element 1 -->
< div class =" child_elem " > </ div >
<!-- Element 2 -->
< div class =" child_elem " > </ div >
<!-- Element 3 -->
< div class =" child_elem " > </ div >
<!-- Element n -->
</ div >即使您使用其他属性,也需要/必须/必须/必须/必须data-jos_stagger必须在父元素中使用jos属性。
data-jos_stagger = true将为父元素自动asign ID,并将其用作子元素的锚点。data-jos_stagger = #id将使用给定的ID作为子元素的锚点。data-jos_stagger_anchor使元素独立于父元素。 data-jos_stagger_seq用于在序列中设置每个元素之间的延迟(一个一个又一次触发),而data-jos_stagger_delay整个元素的总延迟。
示例:惊人的动画
| 属性 | 类型 | 默认 | 描述 | 值 |
|---|---|---|---|---|
| data-jos_animation | 细绳 | 褪色 | 为元素设置动画类型。 | fade , slide , zoom , flip , fade-right , fade-left , fade-up , fade-down , zoom-in-right , zoom-in-left , zoom-in-up , zoom-in-down , zoom-out-right , zoom-out-left , zoom-out-up , zoom-out-down , flip-right , flip-left , flip-up , flip-down , rotate , rotate-right , spin , spin-right , revolve , revolve-right , stretch , stretch-vertical , my-custom-animation |
| data-jos_animation-inverse | 细绳 | 静止的 | 为元素设置逆动画类型。 | fade , slide , zoom , flip , fade-right , fade-left , fade-up , fade-down , zoom-in-right , zoom-in-left , zoom-in-up , zoom-in-down , zoom-out-right , zoom-out-left , zoom-out-up , zoom-out-down , flip-right , flip-left , flip-up , flip-down , rotate , rotate-right , spin , spin-right , revolve , revolve-right , stretch , stretch-vertical , my-custom-animation |
| data-jos_once | 布尔 | 错误的 | 设置该元素是否应仅动画一次。 | true , false |
| data-jos_delay | int | 0 | 设置动画开始的延迟。 | (float: 0-1) & (int: 0, 1, 2, 3, 4, 5) |
| data-jos_duration | 漂浮 | 0.4 | 设置动画播放的持续时间。 | (float: 0-1) & (int: 0, 1, 2, 3, 4, 5) |
| data-jos_timing功能 | 细绳 | 舒适 | 为动画播放设置定时功能。 | ease , ease-in , ease-out , ease-in-out , linear ,线性, step-start , step-end , steps(1, start) , steps(1, end) , cubic-bezier(0.1, 0.7, 1.0, 0.1) , my-custom-timingFunc |
| data-jos_invoke | 细绳 | 无效的 | 将元素滚动到视图时,设置要调用的函数。 | function , myCustomFunction |
| data-jos_invoke_out | 细绳 | 无效的 | 将元素滚动出视图时设置要调用的函数。 | function , myCustomFunction |
| 数据符号 | 布尔&int | 错误的 | 设置该元素是否应仅动画 | (boolean: true, false) & (int: 0-infinity) |
| data-jos_rootmargin | 细绳 | 0%-10%0%-50% | 在滚动时,设置元素在视口中进行动画动画的余量。 | (string: "right% top% left% bottom%") |
| data-jos_rootmargin_top | 细绳 | 0% | 滚动时,设置元素在视口顶部动画的余量。 | (string: "top%") |
| data-jos_rootmargin_bottom | 细绳 | 0% | 滚动时,设置元素在视口底部动画的余量。 | (string: "bottom%") |
| data-jos_scrolldirection | 细绳 | 向下 | 为滚动时在INA视口上为iNA的元素设定方向。 | (string: "up", "down", "none") |
| data-jos_startvisible | 布尔&int | 错误的 | 设置该元素是否应在加载页面时在最终状态(也可以使用延迟)。 | (boolean: true, false) & (int: 0-10000 ms) |
| data-jos_anchor | 细绳 | 无效的 | 设置滚动时在视口中在视口上进行动画元素的锚元素。 | (string: "#elementID") |
| data-jos_scroll | 细绳 | 无效的 | 在滚动时设置元素在视口中进行动画的回调函数。 | function , your_callbackFunction |
| data-jos_stagger | 细绳 | 褪色 | 为孩子滚动时,设置了一个孩子错位元素在视口中进行动画动画的交错动画。 | string , fade |
| data-jos_staggerinverse | 细绳 | 静止的 | 为孩子错失元素设置了交错的逆动画,以便在滚动时在视口(播放动画)时在视口上进行动画。 | string , fade-play |
| data-jos_stagger_anchor | 细绳 | 无效的 | 设置滚动时,设置子错元素在视口上进行动画动画的锚元素。 | string , #elementID |
| data-jos_stagger_seq | 漂浮 | 无效的 | 设置序列延迟,以使子错元素在滚动时在视口上进行动画。 | float , 0-1 |
| data-jos_stagger_delay | 漂浮 | 无效的 | 滚动时,设定了孩子错位元素在视口上进行动画动画的延迟。 | float , 0-1 |
| data-jos_stagger_duration | 漂浮 | 无效的 | 将元素的持续时间设置为孩子在滚动时在视口上的动画。 | float , 0-1 |
| data-jos_stagger_timing-unction | 细绳 | 无效的 | 为子滚动时,设置儿童错位元素在视口上进行动画的定时函数。 | string , ease |
| data-jos_stagger_mirror | 布尔 | 无效的 | 设置镜子动画,以使孩子错位元素在滚动时在视口上进行动画。 | boolean , true , false |
| data-jos_stagger_rootmargin | 细绳 | 无效的 | 在滚动时,设置了一个孩子错位元素在视口上进行动画动画的空间。 | (string: "right% top% left% bottom%") |
| data-jos_stagger_scrolldirection | 细绳 | 无效的 | 滚动时,设定了子错元素在iNA视口上进行动画动画的方向。 | (string: "up", "down", "none") |
| data-jos_stagger_startvisible | 布尔&int | 无效的 | 设置孩子是否应在加载页面时在最终状态开始(也可以延迟工作)。 | (boolean: true, false) & (int: 0-10000 ms) |
| data-jos_stagger_once | 布尔 | 无效的 | 设置该元素是否应仅动画一次或n个计数。 | true , false , int |
| data-jos_stagger_scroll | 细绳 | 无效的 | 设置孩子的回调函数,以便在滚动时在视口上进行动画。 | function , your_callbackFunction |
| data-jos_stagger_invoke | 细绳 | 无效的 | 将子错元素滚动到视图时,设置要调用的功能。 | function , myCustomFunction |
| data-jos_stagger_invoke_out | 细绳 | 无效的 | 设置要调用的功能时,将孩子错位元素滚动出去。 | function , myCustomFunction |
| 方法 | 描述 | 参数 |
|---|---|---|
| init() | 初始化/重置JOS | options = {} (请参阅jos.init(options)) |
| 刷新() | 刷新Jos | 没有任何 |
| 停止() | 停止/暂停Jos | 状态=( 0在最终状态下停止, 1在初始状态下停止-1在当前状态下暂停) |
| 开始() | 开始/恢复JOS服务 | 状态=( 0正常/全启动, -1从当前状态恢复) |
| 破坏() | 销毁Jos实例 | 状态=( 0销毁jos实例不包括样式表, 1与jos -stylesheet一起全面销毁) |
完成并完成了JOS版本后,您可以使用Project Root的以下命令将其捆绑:
# JOS-Animation-Library
# |-dev
# |-dist
# |-bundler
# |-config
# |-export <-- Check this folder for the output files
# |-jos.css
# |-jos.js
# |...
# |-original
# |-bundle.sh <-- Run this file to bundle JOS
# ... # Change/Move to bundler directory
cd ./bundler
# Bundle the project
sh bundle.sh
# View the output files
ls ./export转到问题
甚至可以将其捆绑并进行测试,然后再与世界分享;
(如果您有演示,请给我; )