Web前端开发网

web.fly63.com

首页 资源 工具 文章 教程 栏目
  • 在线搜索
  • 文章标签
  • 文章投稿
  • 关于我们
资源分类
AI智能酷站推荐招聘/兼职框架/库模块/管理移动端UI框架Web-UI框架Js插件CSS相关在线工具建站资源 更多
网站收录 / 问题反馈

DFlex

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

扫一扫分享

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

一个拖放库,适用于所有 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://web.fly63.com/nav/3664

更多»
热门资源
swiper
目前应用较广泛的移动端网页触摸内容滑动js插件
官网
GitHub
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
类似于DFlex的资源
number-flip
一款 js 数字翻转切换插件
官网
GitHub
AR.js
一款应用于 Web 的高效增强现实(AR)库
官网
GitHub
zustand
React 状态管理库
官网
GitHub
Faker.js
一个造假数据的库
官网
GitHub
Waves
超炫交互体验的点击动画效果,采用 Touchstart 与 Touchend 事件,支持移动设备
官网
GitHub
ripplet.js
一款Material design风格点击波特效js插件
官网
GitHub
pangu.js
中英文间插入空格
点击进入
GitHub
rrule.js
用来处理递归规则日历日期的JavaScript库
官网
GitHub
目录

手机扫一扫预览

首页 技术导航 在线工具 技术文章 教程资源 前端标签 AI工具集 前端库/框架

Copyright © 2018 Web前端开发网 All Rights Reserved. 分享编程学习资源(教程/框架/库)、在线工具、技术教程、内容以学习参考为主,助您解决各类实际问题,快速提升专业能力。