fly63前端网

www.fly63.com

首页文章资源工具教程 栏目
  • 关于我们
  • 网站投稿
  • 赞助一下
搜索

在线工具_工作生活好帮手

打造各种简单、易用、便捷的在线工具,网友无需注册和下载安装即可使用

点击查看

关闭

提交网站

DFlex
分享
复制链接
新浪微博
QQ 好友

扫一扫分享

网站地址:https://www.dflex.dev/
GitHub:https://github.com/dflex-js/dflex
网站描述:一款Js拖放库

一个拖放库,适用于所有 JavaScript 框架,实现了增强的转换机制来操作 dom 元素。它是迄今为止互联网上唯一一个操纵 DOM 而不是重建它的库。

DFlex 完全用纯 JavaScript/TypeScript 编写,不依赖于任何特定框架。


特点

  • 动态架构。
  • 无需调用浏览器 api 即可遍历 DOM。
  • 转换元素而不是重新排序 DOM 树。
  • 从点 x 到点 y 的动画运动。
  • 防止拖放布局移位。
  • 与数据流隔离。
  • 无头,因为它只是进行操作的函数。
  • 事件驱动的 API。
  • 分别针对每个 DOM 节点。
  • 可使用 JSON 树而不是平面递归进行扩展。


使用

安装

npm install @dflex/dnd

例子

import { store, DnD } from "@dflex/dnd";

const Task = ({ id, task }) => {
let dndEvent;

// This reference enable DFlex to move the element when required.
const ref = react.useRef();

React.useEffect(() => {
// Wait until component is mounted to get the reference
if (ref) {
store.register({ id, ref: ref.current });
// All the following inputs work fine:
// store.register({ ref: ref.current });
// store.register({ id });
// store.register({ id, ref: ref.current, depth: 0 });
// store.register({ id, ref: ref.current, parentID: "my-first-todo" });
}
}, [ref]);

React.useEffect(() => {
return () => {
// Clear element from the store when unmounted.
store.unregister(id);
};
}, []);

const onMouseMove = (e) => {
if (dndEvent) {
const { clientX, clientY } = e;

// Drag when mouse is moving!
dndEvent.dragAt(clientX, clientY);
}
};

const onMouseUp = () => {
if (dndEvent) {
// This is the end of interactive experience.
dndEvent.endDragging();
dndEvent = null;

document.removeEventListener("mouseup", onMouseUp);
document.removeEventListener("mousemove", onMouseMove);
}
};

const onMouseDown = (e) => {
const { button, clientX, clientY } = e;

// Avoid right mouse click and ensure id
if (typeof button === "number" && button === 0) {
if (id) {
// Add event listeners to the entire document.
// Not just the button boundaries.
document.addEventListener("mouseup", onMouseUp);
document.addEventListener("mousemove", onMouseMove);

// Create DnD instance with no custom options.
dndEvent = new DnD(id, { x: clientX, y: clientY });
}
}
};

return (
<li ref={ref} id={id} onMouseDown={onMouseDown}>
{task}
</li>
);
};

const TodoList = () => {
React.useEffect(() => {
return () => {
// Destroy all elements from the store when unmounted.
store.destroy();
};
}, []);

const tasks = [
{ id: "mtg", msg: "Meet with Laura" },
{ id: "meetup", msg: "Organize weekly meetup" },
{ id: "gym", msg: "Hit the gym" },
{ id: "proj", msg: "The Rosie Project" },
];

return (
<ul id="my-first-todo">
{tasks.map(({ msg, id }) => (
<Task task={msg} key={id} id={id} />
))}
</ul>
);
};


链接: https://fly63.com/nav/3664

more>>
相关栏目
layer
layer是一款口碑极佳的web弹层组件
点击进入GitHub
iScroll.js
IScroll是移动页面上被使用的一款仿系统滚动插件。
官网GitHub
wangEditor
基于javascript和css开发的 Web富文本编辑器
官网GitHub
ueditor
由百度web前端研发部开发所见即所得富文本web编辑器
官网GitHub
highlight
Highlight.js 是一个用 JavaScript 写的代码高亮插件,在客户端和服务端都能工作。
官网GitHub
UglifyJS
一个js 解释器、最小化器、压缩器、美化器工具集
官网GitHub
lozad.js
高性能,轻量级,可配置的懒加载图片工具
官网GitHub
Sortable.js
简单灵活的 JavaScript 拖放排序插件
官网GitHub
validate.js
表单提供了强大的验证功能,让客户端表单验证变得更简单
官网GitHub
Draggin.js
一款兼容移动手机的js拖拽插件
官网GitHub
lazysizes.js
响应式图像延迟加载JS插件【懒加载】
官网GitHub
cropper.js
通过canvas实现图片裁剪
官网GitHub
clipboard.js
浏览器中复制文本到剪贴板的插件,不需要Flash,仅仅2kb
官网GitHub
siema
轻量级简单的纯 Js轮播插件
官网GitHub
Mermrender
用于生成序列和UML图的RESTful渲染管道
官网GitHub
Editor.js
JSON格式输出数据的富文本和媒体编辑器
官网GitHub

手机预览