resizable.js
(function($){
var boundbar=
{
html:"<div class=\"boundbar\" style=\"overflow: hidden; position: absolute;background-color:#09C;\"></div>",
style:"overflow: hidden; position: absolute;background-color:#09C;",
selector:".boundbar:first",
thick:10,
cursor:'pointer',
width:0,
height:0,
offset:null,
resize:false,
boundbar:null,
mousePositionX:0,
mousePositionY:0,
mouseMoveToTopBound:false,
mouseMoveToBottomBound:false,
mouseMoveToLeftBound:false,
mouseMoveToRightBound:false,
};
var target={
context:null,
width:0,
height:0,
offset:null,
resize:false,
pageX:0,
pageY:0,
boundbar:null,
mousePositionX:0,
mousePositionY:0,
mouseMoveToTopBound:false,
mouseMoveToBottomBound:false,
mouseMoveToLeftBound:false,
mouseMoveToRightBound:false,
}
$.fn.extend({
"xhresizable":function(){
$(document).mousemove(function(e) {
target.mousePositionX=e.pageX;
target.mousePositionY=e.pageY;
$("#log").html("");
$("#log").append("position-x:"+target.mousePositionX+"</br>");
$("#log").append("position-y:"+target.mousePositionY+"</br>");
$("#log").append("width:"+target.width+"</br>");
$("#log").append("height:"+target.height+"</br>");
$("#log").append("target.pageX:"+target.pageX+"</br>");
$("#log").append("target.pageY:"+target.pageY+"</br>");
if(target.resize){
var top=target.context.offset.top;
var left=target.context.offset.left;
var width=e.pageX- target.offset.left;
var height=e.pageY- target.offset.top;
if(target.mouseMoveToBottomBound&target.mouseMoveToRightBound){
//右下
$(target.context).css({
"width":width,
"height":height,
});
}
else if(target.mouseMoveToBottomBound){
//下
$(target.context).css({
"width":target.width,
"height":height,
});
}
else if(target.mouseMoveToRightBound){
//右
$(target.context).css({
"width":width,
"height":target.height,
});
}
else{
$(target.context).css({
"width":width,
"height":height,
});
}
}
});
$(document).mouseup(function(e) {
if(target.resize){
target.resize=false;
$("body").append("拖拽拉伸结束</br>");
}
});
//鼠标进入目标区域,添加区域边界
$(this).mouseenter(function(e){
if($(this).children(boundbar.selector).length==0){
$(this).append(boundbar.html);
$(this).children(boundbar.selector).attr("style",boundbar.style);
$(this).children(boundbar.selector).mousedown(function(e){
target.resize=true;
});
$(this).children(boundbar.selector).mouseup(function(e){
target.resize=false;
});
}
});
//鼠标离开目标区域,移除区域边界
$(this).mouseleave(function(e){
$(this).children(boundbar.selector).remove();
});
$(this).mousemove (function(e){
target.context=$(this);
target.width=$(this).width();
target.height=$(this).height();
target.offset = $(this).offset();
target.pageX=e.pageX,
target.pageY=e.pageY,
target.mousePositionX=e.pageX-target.offset.left;
target.mousePositionY=e.pageY-target.offset.top;
target.mouseMoveToTopBound=target.mousePositionY-boundbar.thick<0?true:false;
target.mouseMoveToBottomBound=target.mousePositionY+boundbar.thick>target.height?true:false;
target.mouseMoveToLeftBound=target.mousePositionX-boundbar.thick<0?true:false;
target.mouseMoveToRightBound=target.mousePositionX+boundbar.thick>target.width?true:false;
$("#log").html("");
$("#log").append("position-x:"+target.mousePositionX+"</br>");
$("#log").append("position-y:"+target.mousePositionY+"</br>");
$("#log").append("width:"+target.width+"</br>");
$("#log").append("height:"+target.height+"</br>");
$("#log").append("target.pageX:"+target.pageX+"</br>");
$("#log").append("target.pageY:"+target.pageY+"</br>");
//如果未检测到区域边界,激活目标mouseenter事件(自动添加区域边界及相关事件)
if($(this).children(boundbar.selector).length==0){
$(this).mouseenter();
}
if(target.mouseMoveToBottomBound&target.mouseMoveToRightBound){
//右下
$(boundbar.selector).removeAttr("style").attr("style",boundbar.style).css({
"cursor":"nw-resize",
"right":0,
"bottom":0,
"width":boundbar.thick,
"height":boundbar.thick,
});
}
else if(target.mouseMoveToBottomBound){
//下
$(boundbar.selector).removeAttr("style").attr("style",boundbar.style).css({
"cursor":"n-resize",
"bottom":0,
"left":0,
"width":"100%",
"height":boundbar.thick,
});
}
else if(target.mouseMoveToRightBound){
//右
$(boundbar.selector).removeAttr("style").attr("style",boundbar.style).css({
"cursor":"e-resize",
"top":0,
"right":0,
"width":boundbar.thick,
"height":target.height,
});
}
else{
$(boundbar.selector).removeAttr("style");
}
});
$(this).mousedown(function(e){
target.resize=true;
target.mousePositionX=e.pageX-target.offset.left;
target.mousePositionY=e.pageY-target.offset.top;
});
$(this).mouseup(function(e){
target.resize=false;
});
}
});
})(jQuery);
resizable.js的更多相关文章
- easyloader.js源代码分析
http://www.cnblogs.com/jasonoiu/p/easyloader_source_code_analysis.html Jquery easyui是一个javascript UI ...
- JQuery easyui (3) Resizable(调整大小)组件
Resizable 动态调整元素大小 不依赖其他组件 Resizable的加载方法 <div class="easyui-resizable"></div&g ...
- 3.EasyUI学习总结(三)——easyloader源码分析
easyloader模块是用来加载jquery easyui的js和css文件的,即easyloader可以在调用的时候自动加载当前页面所需的文件,不用再自己引用, 而且它可以分析模块的依赖关系,先加 ...
- easyloader源码
/** * easyloader - jQuery EasyUI * * Licensed under the GPL: * http://www.gnu.org/licenses/gpl.txt * ...
- asp.net gridview 鼠标悬浮提示信息
使用场景: gridview绑定数据,某列数据太多,故超过一定字符,隐藏起来,同时鼠标移到指定列显示其明细信息: 知识点: 1,oderListTbl_DataBound事件中,添加,oderList ...
- asp.net gridview动态添加列,并获取其数据;
1,绑定数据前先动态添加列,见方法CreateGridColumn(只在第一次加载动态添加): 2,gvlist_RowDataBound为对应列添加控件: 前台代码: <%@ Page Lan ...
- ArtDialog简单使用示例
<html><head><meta http-equiv="Content-Type" content="text/html; charse ...
- jquery插件之拖拽改变元素大小
该插件乃本博客作者所写,目的在于提升作者的js能力,也给一些js菜鸟在使用插件时提供一些便利,老鸟就悠然地飞过吧. 此插件旨在实现目前较为流行的拖拽改变元素大小的效果,您可以根据自己的实际需求来设置被 ...
- jqueryui引用出错(base is not a constructor,widget no found)
出错的原因,主要是引用顺序出错. 正确顺序如下: query本身必须放在第一位: <script src="../../../Scripts/Jquery1.7.2/jquery-1. ...
随机推荐
- BZOJ 1799 同类分布
一开始没想出来..一看题解 我艹直接枚举数位的和啊.....怪不得给50s. 还是太蠢. #include<iostream> #include<cstdio> #includ ...
- NOIP 考前 暴力练习
BZOJ 1028 暴力枚举听的那张牌,和那个多余的两张牌,其余的mod3后模拟就可以了 #include <cstdio> ; int n,m,a[Maxn],b[Maxn],cnt,A ...
- iOS按钮设置图片在上文字在下
UIButton同时设置Title和Image后,默认是图片在左文字在右,如下图1,很多情况下我们希望图片在上图片在下,如下图2,只需要简单的几行代码,即可实现. (1)因为需要处理多个按钮,所以将实 ...
- 【已解决】关于SQL2008 “不允许保存更改。您所做的更改要求删除并重新创建以下表。您对无法重新创建的标进行了更改或者启用了‘阻止保存要求重新创建表的更改’” 解决方案
近日在使用SQL Server 2008的过程中,修改已创建完成的表结构时,却一直提示弹出如下提示: 不允许保存更改.您所做的更改要求删除并重新创建以下表.您对无法重新创建的标进行了更改或者启用了“阻 ...
- C#拼接SQL语句,SQL Server 2005+,多行多列大数据量情况下,使用ROW_NUMBER实现的高效分页排序
/// <summary>/// 单表(视图)获取分页SQL语句/// </summary>/// <param name="tableName"&g ...
- js常用的封装函数
1.使用childNodes获取元素的元素节点 //使用childNodes获取元素节点 function cNodes(obj){ var arr=new Array(); for(var i=0; ...
- LintCode Interleaving String
Given three strings: s1, s2, s3, determine whether s3 is formed by the interleaving of s1 and s2. Ex ...
- 一个人的 ClojureScript 技术栈
作者:题叶链接:https://zhuanlan.zhihu.com/p/24425284来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处.今天(昨天)分享完关于 Cloj ...
- React(JSX语法)----动态UI
1.React honws how to bubble and capture events according to the spec,and events passed to your event ...
- Android学习笔记
1.问题:Error when loading the SDK:发现了以元素 'd:skin' 开头的无效内容 方法:删除了android-wear 用sdk\tools\lib下的de ...