定制 webcito/jquery-resize 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

webcito/jquery-resize

Composer 安装命令:

composer require webcito/jquery-resize

包简介

description

README 文档

README

License jQuery

A lightweight jQuery plugin that adds a robust resize event to any HTML element using ResizeObserver. Unlike the native window resize event, this plugin tracks size changes of individual elements and provides detailed information about the change.

example

Features

  • Element-level resize tracking: Monitor any element, not just the window.
  • Detailed change data: Get the axis of change (x, y, or both), new dimensions, previous dimensions, and the calculated difference.
  • Debouncing: Built-in support for debouncing to prevent performance issues during rapid resizing.
  • Debug Mode: Optional visual feedback directly within the element for easier development.
  • Flexible API: Support for both event listeners and direct callback functions.
  • Manual Triggering: Ability to manually trigger a resize check.

Installation

Include jQuery and the plugin in your project:

<script src="path/to/jquery.min.js"></script>
<script src="dist/jquery-resize.min.js"></script>

Or via Composer:

composer require webcito/jquery-resize

Usage

Basic Initialization

Initialize the plugin on your elements:

$('.my-element').resize();

With Event Listener

The plugin triggers a standard jQuery resize event but passes additional arguments to the handler:

$('.my-element').on('resize', function(event, axis, afterSizes, beforeSizes, diffSizes) {
    console.log('Resize axis:', axis); // 'x', 'y', or 'both'
    console.log('New size:', afterSizes); // { width: 100, height: 100 }
    console.log('Old size:', beforeSizes); // { width: 90, height: 100 }
    console.log('Difference:', diffSizes); // { width: 10, height: 0 }
});

With Callback Function

You can pass a callback directly to the .resize() method:

$('.my-element').resize(function(axis, afterSizes, beforeSizes, diffSizes) {
    console.log('Resized on axis:', axis);
});

Configuration Options

You can pass an options object to the initialization:

$('.my-element').resize({
    wait: 300,   // Debounce wait time in milliseconds (default: 400)
    debug: true  // Show dimension info inside the element (default: false)
});

Global Configuration

Set default values for all future initializations:

$.setupResize.setDefaults({
    wait: 200,
    debug: false
});

Manual Trigger

Force a resize calculation and event trigger:

$('.my-element').resize('resize');

API Reference

Arguments for Event/Callback

Argument Type Description
axis string The axis that changed: 'x', 'y', or 'both'.
afterSizes object The new dimensions: { width: number, height: number }.
beforeSizes object The dimensions before the resize: { width: number, height: number }.
diffSizes object The difference between new and old sizes: { width: number, height: number }.

Options

Option Type Default Description
wait number 400 Debounce time in milliseconds.
debug boolean false If true, overlays resize info on the element.

Requirements

  • jQuery 3.0 or higher
  • Modern browser with ResizeObserver support (Chrome 64+, Firefox 69+, Safari 13.1+, Edge 79+)

License

This project is licensed under the proprietary License - see the composer.json file for details.

统计信息

  • 总下载量: 14
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2023-12-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固