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. ...
随机推荐
- ios中自定义cell 设置cell的分组结构
ios系统默认的cell并不能满足我们的需求 这个时候就需要自定义我们的cell 自定义cell为分组的时候 需要设置分组样式 以下是我常用分组的二种方法: 第一是 在自定义的UITableView ...
- asp.net使用控件datagrid实现表头单元格合并
合并的要点: 1.datagid的单元格合并原理是table中tr,td的布局实现; 2.合并的时机实在其datagridcreate事件中实现; 3.认识一个对象TableCellCollectio ...
- php大力力 [049节] php函数implode()
implode()[1] 函数返回一个由数组元素组合成的字符串. 注释:implode() 函数接受两种参数顺序.但是由于历史原因,explode() 是不行的,您必须保证 separator 参数 ...
- Android WebView 保存cache至External Storage
源博客: http://www.devahead.com/blog/2012/01/saving-the-android-webview-cache-on-the-sd-card/ 其中心思想是,通过 ...
- H - Lazier Salesgirl
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit Status Practic ...
- 【JS】键盘鼠标事件
一,键盘 keydown 表示按下键盘 keypress 表示按下键盘 keyup 表示键盘弹起 这三者的区别分别表现在发生的 先后顺序,获取到的键盘按钮值,已经对输入框的文本取值这三方面 先后顺序: ...
- Myelipcse导入Maven项目: version of spring facet could not be detected
在导入已存在的maven web项目的时候,总是出现Versions of Spring facet could not be detected的问题. 查资料知道有两种解决方法:一个是什么在项目根目 ...
- 使用html模板
创建html---点击next--选择写好的模板
- 2016年中国大学生程序设计竞赛(合肥)-重现赛1001 HDU 5961
传递 Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submiss ...
- 集合视图 UICollectionView
什么是UICollectionView UICollectionView是一种新的数据展示方式,简单来说可以把他理解成多列的UITableView(请一定注意这是UICollectionView的最最 ...