|
|
3 zile în urmă | |
|---|---|---|
| doc | 3 zile în urmă | |
| .gitignore | 4 zile în urmă | |
| LICENSE | 4 zile în urmă | |
| README.md | 3 zile în urmă | |
| animal.js | 3 zile în urmă | |
| layer.js | 3 zile în urmă | |
| main.go | 4 zile în urmă | |
| test.html | 4 zile în urmă | |
| xjs.js | 3 zile în urmă |
一个“最小可用、可直接用 <script> 引入”的现代化前端工具库,面向 网站 / H5 / App WebView 的轻量组件集成场景。
核心设计理念是 "All in One Selector" —— 一个全局函数 animal (可别名为 $) 既是选择器,也是功能入口。
animal('.selector') 统一管理动画与交互。<!-- 1. 引入动画引擎 (导出全局变量 animal) -->
<script src="animal.js"></script>
<!-- 2. 引入弹窗组件 (导出全局变量 Layer) -->
<script src="layer.js"></script>
为了获得最佳体验,建议将 animal 赋值给 $ (或其他你喜欢的简写)。
// 建立简写别名
const $ = animal;
.animate)$('.box').animate({
x: 200, // 自动处理 transform
scale: 1.5,
opacity: 0.5,
backgroundColor: '#f00',
duration: 800,
easing: 'ease-out'
}).then(() => {
console.log('Animation done');
});
.layer)直接在选择器上绑定点击弹窗事件。
// 点击按钮触发弹窗
$('.btn-delete').layer({
title: '确定删除?',
text: '此操作不可恢复',
icon: 'warning',
showCancelButton: true
});
.draw)$('path').draw({
duration: 1500,
easing: 'ease-in-out'
});
无需配置复杂的贝塞尔曲线,使用物理参数即可。
$('.card').animate({
y: [100, 0],
easing: { stiffness: 200, damping: 10 }
});
元素进入屏幕可视区域时自动播放。
$('.fade-up').inViewAnimate({
y: [50, 0],
opacity: [0, 1],
duration: 600
}, { once: true });
将动画进度绑定到页面滚动条。
const controls = $('.progress').animate({
width: ['0%', '100%'],
autoplay: false
});
// 使用静态方法 $.scroll 绑定
$.scroll(controls);
编排串行复杂的动画序列。
const tl = $.timeline();
tl.add('.box-1', { x: 100 })
.add('.box-2', { x: 100 }, '-=200') // 提前 200ms
.play();
虽然推荐使用 $('.el').layer(...) 绑定事件,但你也完全可以通过全局对象手动调用。
$.layer({
title: 'Hello World',
text: 'This is a message from $.layer()'
});
$.layer({
title: '提交表单?',
showCancelButton: true
}).then((res) => {
if (res.isConfirmed) {
$.layer({ title: '提交成功!', icon: 'success' });
}
});
// 传入 DOM 元素
$.layer({
title: 'Custom Content',
content: document.querySelector('#my-template')
});
// 或者传入 HTML 字符串
$.layer({
html: '<strong>Bold Text</strong><br>New line'
});
| 参数名 | 说明 |
|---|---|
title |
标题 |
text |
正文 (纯文本) |
html |
正文 (HTML 字符串) |
content |
正文 (DOM 元素或 CSS 选择器) |
icon |
success / error / warning |
showCancelButton |
是否显示取消按钮 (默认 false) |
confirmButtonText |
确认按钮文字 (默认 OK) |
cancelButtonText |
取消按钮文字 (默认 Cancel) |
| 调用方式 | 描述 |
|---|---|
$(selector) |
核心选择器,返回 Selection 对象 |
Selection.animate(params) |
执行动画 |
Selection.draw(params) |
SVG 描边动画 |
Selection.layer(options) |
绑定点击弹窗 |
Selection.inViewAnimate(...) |
进入视口触发动画 |
$.spring(config) |
创建物理缓动函数 |
$.timeline() |
创建时间轴 |
$.scroll(controls) |
绑定滚动驱动 |
$.layer(options) |
直接弹出窗口 (别名 $.fire) |