npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

drag-resize-box

v1.0.11

Published

一款无任何依赖、且支持拖拽和缩放功能的原生组件。

Downloads

15

Readme

drag-resize-box

一款无任何依赖库、且支持拖拽和缩放功能的原生组件。

支持 import 和浏览器 script 标签

使用方式一:

通过 script 标签引入 dist 目录下的 DragResizeBox.min.js 文件。

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>功能演示</title>
    <style>
      .box {
        width: 200px;
        height: 200px;
        background-color: red;
      }
    </style>
    <script src="./dist/DragResizeBox.min.js"></script>
  </head>
  <body>
    <div class="box"></div>

    <script>
      const boxEl = document.querySelector(".box");
      new DragResizeBox(boxEl, { left: 100, top: 100 });
    </script>
  </body>
</html>

使用方式二:

下载 npm 包,通过 import 导入到自己的项目中。

npm install drag-resize-box
import DragResizeBox from "drag-resize-box";

new DragResizeBox(domEl);

DragResizeBox 类

语法

new DragResizeBox(domEl);

new DragResizeBox(domEl, options);

参数

domEl(必选):需要支持拖拽操作的 DOM 元素。

options(可选):一个对象,用于提供相关配置选项。

  • drag:布尔类型,是否开启拖拽模式,默认值为 true
  • zoom:布尔类型,是否开启缩放模式,默认值为 true
  • minWidth:数值类型,最小缩放宽度,默认值为 0(单位:px)
  • minHeight:数值类型,最小缩放高度,默认值为 0(单位:px)
  • zIndex:数值类型,拖拽元素层级,默认值为 9999
  • dragSelector:字符串类型,设置拖拽部分,传入 CSS 选择器,默认值为 null
  • left:数值类型,初始距离浏览器窗口左边的距离,默认值为 0(单位:px)
  • top:数值类型,初始距离浏览器窗口上边的距离,默认值为 0(单位:px)
  • cornerSize:数值类型,角缩放控制区域的尺寸,默认值为 16(单位:px)
  • borderSize:数值类型,边缩放控制区域的尺寸,默认值为 12(单位:px)
  • center:布尔类型,拖拽元素初始位置是否居中,默认值为 false
  • limitZoomArea:数组类型,限制缩放区域,默认值为 [],可填值:left, right, top, bottom, leftTop, leftBottom, rightTop, rightBottom

DragResizeBox 实例方法

setFullScreen()

为DOM元素设置全屏。

exitFullScreen()

DOM元素退出全屏。

setMinWidth()

为DOM元素设置最小宽度,若当前宽度小于最小宽度,则立即设置DOM元素的宽度为最小宽度。

setMinHeight()

为DOM元素设置最小高度,若当前高度小于最小高度,则立即设置DOM元素的高度为最小高度。

reset()

还原DOM元素的状态为实例化之前,调用此方法后实例将失活(即无法调用任何方法)。

DragResizeBox 事件

通过添加事件监听函数,你可以获取到 DOM 元素的自身的宽高以及相对于浏览器窗口的left和top值。

resize 事件

在DOM元素被缩放时触发。

const dragResizeBox = new dragResizeBox(domEl);

// 添加resize事件监听
dragResizeBox.addEventListener("resize", (event) => {
  console.log("事件名:", event.name);
  console.log("事件数据:", event.data);
});

// 移除resize事件监听
dragResizeBox.removeEventListener("resize");

drag 事件

在DOM元素被拖拽时触发。

const dragResizeBox = new dragResizeBox(domEl);

// 添加drag事件监听
dragResizeBox.addEventListener("drag", (event) => {
  console.log("事件名:", event.name);
  console.log("事件数据:", event.data);
});

// 移除drag事件监听
dragResizeBox.removeEventListener("drag");