今天写了一天这个jquery插件:
可以实现对div进行拖拽来调整大小的功能。
复制代码 代码如下:
(function ($) {
$.fn.dragDivResize = function () {
var deltaX, deltaY, _startX, _startY;
var resizeW, resizeH;
var size = 20;
var minSize = 10;
var scroll = getScrollOffsets();
var _this = this;
for (var i = 0; i < _this.length; i++) {
var target = this[i];
$(target).on("mouseover mousemove", overHandler);
}
function outHandler() {
for (var i = 0; i < _this.length; i++) {
target.style.outline = "none";
}
document.body.style.cursor = "default";
}
function overHandler(event) {
target = event.target || event.srcElement;
var startX = event.clientX + scroll.x;
var startY = event.clientY + scroll.y;
var w = $(target).width();
var h = $(target).height();
_startX = parseInt(startX);
_startY = parseInt(startY);
if ((0 < target.offsetLeft + w - _startX && target.offsetLeft + w - _startX < size) || (0 < target.offsetTop + h - _startY && target.offsetTop + h - _startY < size)) {
target.style.outline = "2px dashed #333";
if ((0 > target.offsetLeft + w - _startX || target.offsetLeft + w - _startX > size) && 0 < target.offsetTop + h - _startY && target.offsetTop + h - _startY < size) {
resizeW = false;
resizeH = true;
document.body.style.cursor = "s-resize";
}
if (0 < target.offsetLeft + w - _startX && target.offsetLeft + w - _startX < size && (0 > target.offsetTop + h - _startY || target.offsetTop + h - _startY > size)) {
resizeW = true;
resizeH = false;
document.body.style.cursor = "w-resize";
}
if (0 < target.offsetLeft + w - _startX && target.offsetLeft + w - _startX < size && 0 < target.offsetTop + h - _startY && target.offsetTop + h - _startY < size) {
resizeW = true;
resizeH = true;
document.body.style.cursor = "se-resize";
}
$(target).on('mousedown', downHandler);
} else {
resizeW = false;
resizeH = false;
$(target).off('mousedown', downHandler);
}
}
function downHandler(event) {
target = event.target || event.srcElement;
var startX = event.clientX + scroll.x;
var startY = event.clientY + scroll.y;
_startX = parseInt(startX);
_startY = parseInt(startY);
if (document.addEventListener) {
document.addEventListener("mousemove", moveHandler, true);
document.addEventListener("mouseup", upHandler, true);
} else if (document.attachEvent) {
target.setCapture();
target.attachEvent("onlosecapeture", upHandler);
target.attachEvent("onmouseup", upHandler);
target.attachEvent("onmousemove", moveHandler);
}
if (event.stopPropagation) {
event.stopPropagation();
} else {
event.cancelBubble = true;
}
if (event.preventDefault) {
event.preventDefault();
} else {
event.returnValue = false;
}
}
function moveHandler(e) {
if (!e) e = window.event;
var w, h;
var startX = parseInt(e.clientX + scroll.x);
var startY = parseInt(e.clientY + scroll.y);
target = target || e.target || e.srcElement;
if (target == document.body) {
return;
}
if (resizeW) {
deltaX = startX - _startX;
w = $(target).width() + deltaX < minSize "px";
_startX = startX;
}
if (resizeH) {
deltaY = startY - _startY;
h = $(target).height() + deltaY < minSize "px";
_startY = startY;
}
if (e.stopPropagation) {
e.stopPropagation();
} else {
e.cancelBubble = true;
}
}
function upHandler(e) {
if (!e) {
e = window.event;
}
resizeW = false;
resizeH = false;
target = e.target || e.srcElement;
$(target).on("mouseout", outHandler);
if (document.removeEventListener) {
document.removeEventListener("mousemove", moveHandler, true);
document.removeEventListener("mouseup", upHandler, true);
} else if (document.detachEvent) {
target.detachEvent("onlosecapeture", upHandler);
target.detachEvent("onmouseup", upHandler);
target.detachEvent("onmousemove", moveHandler);
target.releaseCapture();
}
if (e.stopPropagation) {
e.stopPropagation();
} else {
e.cancelBubble = true;
}
}
function getScrollOffsets(w) {
w = w || window;
if (w.pageXOffset != null) {
return { x: w.pageXOffset, y: w.pageYOffset };
}
var d = w.document;
if (document.compatMode == "CSS1Compat") {
return { x: d.documentElement.scrollLeft, y: d.documentElement.scrollTop };
}
return { x: d.body.scrollLeft, y: d.body.scrollTop };
}
}
}(jQuery));
jQuery("div").dragDivResize();
记录一下今天的劳动成果,可能会有很多不成熟的地方,欢迎大家来指正,谢谢!
以上就是本文的全部内容了,希望大家能够喜欢。
jQuery,拖拽,DIV
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
- Fine乐团《废墟游乐》[320K/MP3][105.13MB]
- 万山红.2009-花开原野万山红Vol.1-2【柏菲】2CD【WAV+CUE】
- 曾庆瑜1992-18首中英文经典全集[台湾派森][WAV整轨]
- 【上扬爱乐】群星-TheSoundsofLS35AVol.4情迷4【低速原抓WAV分轨】
- Fine乐团《废墟游乐》[Hi-Res][24bit 48kHz][FLAC/分轨][767.04MB]
- Cicada《回返 (十五周年自选集)》[320K/MP3][93.87MB]
- Cicada《回返 (十五周年自选集)》[Hi-Res][24bit 48kHz][FLAC/分轨][466.75MB]
- 郑智化.2024-不思议【智在上作】【FLAC分轨】
- 罗文.2015-NEW.XRCD精丫华星】【WAV+CUE】
- 许秋怡.1995-电影少女【丽音唱片】【FLAC分轨】
- 【中国艺术歌曲典藏】温雅欣《她比烟花寂寞》紫银合金SQCD【低速原抓WAV+CUE】
- 张国荣《FinalEncounter》头版限量编号MQA-UHQ[低速原抓WAV+CUE].
- 发烧萨克斯-雪国之春(SRS+WIZOR)[原抓WAV+CUE]
- 王铮亮《慢人理论》[320K/MP3][175.31MB]
- 王铮亮《慢人理论》[FLAC/分轨][524.11MB]