html 拖拽修改控件大小,jquery实现div边界拖拽控制大小.html

这篇博客介绍了一个使用CSS和JavaScript实现的可拖动分隔条的示例,允许用户自定义页面左右两侧区域的大小。通过监听鼠标事件,动态调整两侧区块的宽度,提供了一种交互式的布局解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

body,

html {

width: 100%;

height: 100%;

margin: 0;

padding: 0;

}

#container {

width: 100%;

height: 100%;

/* Disable selection so it doesn't get annoying */

-webkit-touch-callout: none;

-webkit-user-select: none;

-khtml-user-select: none;

-moz-user-select: moz-none;

-ms-user-select: none;

user-select: none;

}

#container #left {

position: absolute;

left: 0;

top: 0;

bottom: 0;

right: 100px;

background: red;

}

#container #right {

position: absolute;

right: 0;

top: 0;

bottom: 0;

width: 200px;

background: blue;

}

#container #handle {

position: absolute;

left: -4px;

top: 0;

bottom: 0;

width: 8px;

cursor: w-resize;

}

This is the left side's content!

var isResizing = false,

lastDownX = 0;

$(function() {

var container = $('#container'),

left = $('#left'),

right = $('#right'),

handle = $('#handle');

handle.on('mousedown', function(e) {

isResizing = true;

lastDownX = e.clientX;

});

$(document).on('mousemove', function(e) {

// we don't want to do anything if we aren't resizing.

if (!isResizing)

return;

var offsetRight = container.width() - (e.clientX - container.offset().left);

left.css('right', offsetRight);

right.css('width', offsetRight);

}).on('mouseup', function(e) {

// stop resizing

isResizing = false;

});

});

一键复制

编辑

Web IDE

原始数据

按行查看

历史

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值