(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的更多相关文章

  1. easyloader.js源代码分析

    http://www.cnblogs.com/jasonoiu/p/easyloader_source_code_analysis.html Jquery easyui是一个javascript UI ...

  2. JQuery easyui (3) Resizable(调整大小)组件

    Resizable  动态调整元素大小  不依赖其他组件 Resizable的加载方法 <div class="easyui-resizable"></div&g ...

  3. 3.EasyUI学习总结(三)——easyloader源码分析

    easyloader模块是用来加载jquery easyui的js和css文件的,即easyloader可以在调用的时候自动加载当前页面所需的文件,不用再自己引用, 而且它可以分析模块的依赖关系,先加 ...

  4. easyloader源码

    /** * easyloader - jQuery EasyUI * * Licensed under the GPL: * http://www.gnu.org/licenses/gpl.txt * ...

  5. asp.net gridview 鼠标悬浮提示信息

    使用场景: gridview绑定数据,某列数据太多,故超过一定字符,隐藏起来,同时鼠标移到指定列显示其明细信息: 知识点: 1,oderListTbl_DataBound事件中,添加,oderList ...

  6. asp.net gridview动态添加列,并获取其数据;

    1,绑定数据前先动态添加列,见方法CreateGridColumn(只在第一次加载动态添加): 2,gvlist_RowDataBound为对应列添加控件: 前台代码: <%@ Page Lan ...

  7. ArtDialog简单使用示例

    <html><head><meta http-equiv="Content-Type" content="text/html; charse ...

  8. jquery插件之拖拽改变元素大小

    该插件乃本博客作者所写,目的在于提升作者的js能力,也给一些js菜鸟在使用插件时提供一些便利,老鸟就悠然地飞过吧. 此插件旨在实现目前较为流行的拖拽改变元素大小的效果,您可以根据自己的实际需求来设置被 ...

  9. jqueryui引用出错(base is not a constructor,widget no found)

    出错的原因,主要是引用顺序出错. 正确顺序如下: query本身必须放在第一位: <script src="../../../Scripts/Jquery1.7.2/jquery-1. ...

随机推荐

  1. 【转】C#多线程

    C#中的多线程编程 C#是.Net平台的通用开发工具,它能够建造所有的.Net应用.在.Net中所有线程都运行在应用程序域(AppDomain)中,这也许让你想到Win32进程,实际上它们还是有很大的 ...

  2. vi学习 常用命令-新建-复制-剪切-粘贴

    mkdir /home/brandon.du/desktop/mylinux/test_1.txt   ---------mkdir新建文件夹 rm /home/brandon.du/desktop/ ...

  3. document与window的区别

    [window对象] 它是一个顶层对象,而不是另一个对象的属性,即浏览器的窗口. 属性 defaultStatus 缺省的状态条消息 document 当前显示的文档(该属性本身也是一个对象) fra ...

  4. css3 视距-perspective

           视距-用来设置用户与元素3d空间Z平面之间的距离. 实例1:       HTML: <div class="perspective"> <h3&g ...

  5. 缓存和sd卡的路径(原)

    在需要存储的时候,路径的问题是初学者比较迷惑的,下面是对于getCacheDir().getFilesDir().getExternalFilesDir().getExternalCacheDir() ...

  6. SQL if exists database总是出现语法错误

    SQL if exists总是出现语法错误.望高手纠正._百度知道 http://zhidao.baidu.com/link?url=7VyzcX0V1A3lhBQ1emNt2sTk7QGDuijOq ...

  7. Qt之qInstallMessageHandler(重定向至文件)

    简述 在Qt之qInstallMessageHandler(输出详细日志)一节中,我们讲解了如何使用自定义消息处理程序输出调试信息,而且可以很直观.很方便的得到输出代码所在的文件.函数.行号等信息. ...

  8. 创建SO bapi

    转自http://blog.sina.com.cn/s/blog_1647b3eff0102wi32.html 1.创建销售订单使用的BAPI BAPI_SALESORDER_CREATEFROMDA ...

  9. js 递归学习

    作用:将一些复制的算法变为简单,比如:(举例子)计算数组 var  a =[1,3,4,6,7,8]的长度:求 5!的值,也可以做搜索用等. //求数组的长度function len(arry){ i ...

  10. VS 2005 修复重置(深度重置)

    /resetuserdata 参数 如果 Visual Studio 在运行时被损坏,且无法从损坏状态进行恢复,您可以使用此参数将 Visual Studio 重置到其使用之初的状态.这些问题的例子可 ...