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. ...
随机推荐
- 一、Android屏幕的计量单位
px :是屏幕的像素点in :英寸mm:毫米pt :磅,1/72英寸dp :一个基于density的抽象单位,如果一个160dpi的屏幕,1dp=1pxdip :等同于dpsp :同dp ...
- Mac小知识(不定时更新)
1.显示隐藏文件夹(在mac命令行中输入以下代码即可): 1)显示隐藏文件夹 defaults write com.apple.finder AppleShowAllFiles Yes &&a ...
- 彻底弄懂Activity四大启动模式
最近有几位朋友给我留言,让我谈一下对Activity启动模式的理解.我觉得对某个知识点的理解必须要动手操作才能印象深刻,所以今天写一篇博文,结合案例理解Activity启动模式.由于之前看过" ...
- HDU5840 (分块+树链剖分)
Problem This world need more Zhu 题目大意 给一颗n个点的有点权的树,有m个询问,对于每个询问u,v,k,首先将点u到点v的最短路径上的所有点按顺序编号,u的编号为1, ...
- Struts2框架下表单数据的流向以及映射关系
本例框架很简单:默认页面为用户登录界面login.jsp,提交后由action类LoginAction.java来判断成功或失败,登录结果分别由success.jsp和failure.jsp呈现. 一 ...
- Git 的详细使用
本文翻译自Understanding Git Source Control in Xcode (译者myShire)欢迎您加入我们的翻译小组. 在应用程序开发过程中,很重要的一部分工作就是如何进行 ...
- PAT (Advanced Level) Practise:1027. Colors in Mars
[题目链接] People in Mars represent the colors in their computers in a similar way as the Earth people. ...
- SQL --Chapter 04 数据更新
数据的插入(INSERT语句的使用方法) INSERT INTO ShohinIns (shohin_id, shohin_mei, shohin_bunrui, hanbai_tanka, 原则上, ...
- 解决Android SDK Content Loader 0%的问题
在Android的开发过程中,应该说大多数人都遇到过此问题. 具体原因不得而知,在workspace中导入了太多的工程可能是其中一个原因. 网上有很多针对此问题的解决方法,对于我自己而言,下面两个方法 ...
- mysqldump-info
其实很多东西都能在info里面找到非常详细的说明,只是,我们太忙了,只想要一个答案,而无心去看而已,所以呢,就把用得到的都看一下来记录吧. 命令模式:mysqldump [options] [db_n ...