(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. ruby on rails 安装

    第一种方案: 1. 下载ruby    Ruby21-x64 2. 1 gem sources --remove http://rubygems.org 2. 2 gem sources -a htt ...

  2. 禁用 baloo_file_extractor 加速 ubuntu 14.04 (KDE)

    在复制了一堆零散文件后,系统同然变得奇卡,看看cpu和ram都占用不高,但看到这个进程 baloo_file_extractor 时不时地冒一下泡,怀疑是它在频繁访问硬盘.禁止它自动启动的方式: $ ...

  3. 2014 项目中用到batik

    现在手头上的项目用到batik编程,用的maven管理jar包,要在pom.xml中dependencies标签下添加一下配置(batik编程使用的顶层jar包) <dependency> ...

  4. 如何启动一个Java Web应用

    最近使用一个开源项目写程序,为了方便沟通加入了相关的讨论群,经常在群里看到有人问项目怎么启动不起来,在此提供一下解决思路1.查看自己下载的项目目录通过文件夹结构,你能够看出来你下载的是一个maven项 ...

  5. Block对象

    背景:回调机制中回调设置代码和回调方法的具体实现无法写在同一段代码中.Mac OS X 10.6和iOS4种引入了Block对象.Block对象看上去是一段代码,但是可以当作数据来传递. 定义Bloc ...

  6. AllanCodeMaker 代码生成器 release0.9.0 下载 支持C#,Java,可自订模板

    接我前面的文章(2015-8-18 更新下载链接) http://www.cnblogs.com/allanyang/p/4687534.html 这几天事情多,所以改动不大,修改了一些小细节.公司那 ...

  7. 黑马程序员:Java编程_7K面试题之银行业务调度系统

    =========== ASP.Net+Android+IOS开发..Net培训.期待与您交流!=========== 模拟实现银行业务调度系统逻辑,具体需求如下: 银行内有6个业务窗口,1 - 4号 ...

  8. Fedora下的解压

    Fedora下解压缩的相关操作 以下内容转载自互联网,仅供个人学习之用. 对于刚刚接触Linux的人来说,一定会给Linux下一大堆各式各样的文件名给搞晕.别个不说,单单就压缩文件为例,我们知道在Wi ...

  9. Lua小技巧

    来公司以后,业务逻辑都用lua写.写了好长时间了,到最近才觉得有点掌握了Lua的灵活.最近用Lua写了个类似集合一样的东西,如果两次向集合里放入同一个元素,就会报错,方便检查配置.代码如下: -- k ...

  10. CloudStack中云主机的UTC时间转为本地时间

    CloudStack项目中使用的时间是UTC时间,具体什么是UTC时间大家可以百度,但是我们需要的时间是正常的时间,所以在国泰君安开发测试云中,同步资源管理中虚拟机的同步管理,需要对虚拟机的时间格式化 ...