JQ弹出框移动-插件分享~~~
<script src="js/jQuery8.3.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".happy").click(function(){
$(".loadbox").fadeIn("slow");
});
$(".no").click(function(){
$(".loadbox").fadeOut("slow");
});
$(".loadbox").easydrag();
});
</script>
插件网络下载:<script type="text/javascript" src="js/jquery.beta.js"></script>
(function($){ // to track if the mouse button is pressed
var isMouseDown = false; // to track the current element being dragged
var currentElement = null; // callback holders
var dropCallbacks = {};
var dragCallbacks = {}; // bubbling status
var bubblings = {}; // global position records
var lastMouseX;
var lastMouseY;
var lastElemTop;
var lastElemLeft; // track element dragStatus
var dragStatus = {}; // if user is holding any handle or not
var holdingHandler = false; // returns the mouse (cursor) current position
$.getMousePosition = function(e){
var posx = 0;
var posy = 0; if (!e) var e = window.event; if (e.pageX || e.pageY) {
posx = e.pageX;
posy = e.pageY;
}
else if (e.clientX || e.clientY) {
posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
} return { 'x': posx, 'y': posy };
}; // updates the position of the current element being dragged
$.updatePosition = function(e) {
var pos = $.getMousePosition(e); var spanX = (pos.x - lastMouseX);
var spanY = (pos.y - lastMouseY); $(currentElement).css("top", (lastElemTop + spanY));
$(currentElement).css("left", (lastElemLeft + spanX));
}; // when the mouse is moved while the mouse button is pressed
$(document).mousemove(function(e){
if(isMouseDown && dragStatus[currentElement.id] != 'false'){
// update the position and call the registered function
$.updatePosition(e);
if(dragCallbacks[currentElement.id] != undefined){
dragCallbacks[currentElement.id](e, currentElement);
} return false;
}
}); // when the mouse button is released
$(document).mouseup(function(e){
if(isMouseDown && dragStatus[currentElement.id] != 'false'){
isMouseDown = false;
if(dropCallbacks[currentElement.id] != undefined){
dropCallbacks[currentElement.id](e, currentElement);
} return false;
}
}); // register the function to be called while an element is being dragged
$.fn.ondrag = function(callback){
return this.each(function(){
dragCallbacks[this.id] = callback;
});
}; // register the function to be called when an element is dropped
$.fn.ondrop = function(callback){
return this.each(function(){
dropCallbacks[this.id] = callback;
});
}; // disable the dragging feature for the element
$.fn.dragOff = function(){
return this.each(function(){
dragStatus[this.id] = 'off';
});
}; // enable the dragging feature for the element
$.fn.dragOn = function(){
return this.each(function(){
dragStatus[this.id] = 'on';
});
}; // set a child element as a handler
$.fn.setHandler = function(handlerId){
return this.each(function(){
var draggable = this; // enable event bubbling so the user can reach the handle
bubblings[this.id] = true; // reset cursor style
$(draggable).css("cursor", ""); // set current drag status
dragStatus[draggable.id] = "handler"; // change handle cursor type
$("#"+handlerId).css("cursor", "move"); // bind event handler
$("#"+handlerId).mousedown(function(e){
holdingHandler = true;
$(draggable).trigger('mousedown', e);
}); // bind event handler
$("#"+handlerId).mouseup(function(e){
holdingHandler = false;
});
});
} // set an element as draggable - allowBubbling enables/disables event bubbling
$.fn.easydrag = function(allowBubbling){ return this.each(function(){ // if no id is defined assign a unique one
if(undefined == this.id || !this.id.length) this.id = "easydrag"+(new Date().getTime()); // save event bubbling status
bubblings[this.id] = allowBubbling ? true : false; // set dragStatus
dragStatus[this.id] = "on"; // change the mouse pointer
$(this).css("cursor", "move"); // when an element receives a mouse press
$(this).mousedown(function(e){ // just when "on" or "handler"
if((dragStatus[this.id] == "off") || (dragStatus[this.id] == "handler" && !holdingHandler))
return bubblings[this.id]; // set it as absolute positioned
$(this).css("position", "absolute"); // set z-index
$(this).css("z-index", parseInt( new Date().getTime()/1000 )); // update track variables
isMouseDown = true;
currentElement = this; // retrieve positioning properties
var pos = $.getMousePosition(e);
lastMouseX = pos.x;
lastMouseY = pos.y; lastElemTop = this.offsetTop;
lastElemLeft = this.offsetLeft; $.updatePosition(e); return bubblings[this.id];
});
});
}; })(jQuery);
插件
JQ弹出框移动-插件分享~~~的更多相关文章
- Bootstrap 弹出框(Popover)插件
Bootstrap 弹出框(Popover)插件与Bootstrap 提示工具(Tooltip)插件类似,提供了一个扩展的视图,用户只需要把鼠标指针悬停到元素上面即可.弹出框的内容完全由Bootstr ...
- 弹出框layer插件
有时候我们在网页制作中需要引用各种弹出框,弹出框的展现形式多种多样.可以是弹出图片,视频,文字,也可以是弹出图片轮播等形式: 弹出框插件——layer使用方法(其实官方文档中已经介绍的很详细): 下载 ...
- 弹出框sweetalert插件的简单使用
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 玩转Bootstrap(JS插件篇)-第1章 模态弹出框 :1-3 模态弹出框
模态弹出框(Modals) 这一小节我们先来讲解一个“模态弹出框”,插件的源文件:modal.js. 右侧代码编辑器(30行)就是单独引入 bootstrap 中发布出的“modal.js”文件. 样 ...
- JS弹出框插件zDialog再次封装
zDialog插件网址:http://www.jq22.com/jquery-info2426 再次封装zDialog的代码: (function ($) { $.extend({ iDialog: ...
- Bootstrap 弹出框和警告框插件
一.弹出框 弹出框即点击一个元素弹出一个包含标题和内容的容器. //基本用法 <button class="btn btn-lg btn-danger" type=" ...
- jQuery+css3弹出框插件
先来看DEMO:https://codepen.io/jonechen/pen/regjGG 插件的开发很简单,运用了CSS3的动画效果,并且弹出框的内容可以自定义.插件的默认配置参数有三个: var ...
- JavaScript插件——弹出框
(JavaScript插件——弹出框) 前言 阅读之前您也可以到Bootstrap3.0入门学习系列导航中进行查看http://www.cnblogs.com/aehyok/p/3404867.htm ...
- Bootstrap入门(二十九)JS插件6:弹出框
Bootstrap入门(二十九)JS插件6:弹出框 加入小覆盖的内容,像在iPad上,用于存放非主要信息 弹出框是依赖于工具提示插件的,那它也和工具提示是一样的,是需要初始化才能够使用的 首先我们引入 ...
随机推荐
- Python的文本数据
字符串的一些方法! 1.text.endswith(".jpg") 如果字符串是以给定子字符串结尾的,就返回值True. 2. text.upper(): ...
- 总结一下在ASP.NET中开发网站的一般步骤
1.打开Miscosoft Visual Studio2010 2.新建网页添加新项 3.设计网页 4.添加窗体控件 5.优化页面 6.调试网页
- C#.NET 字符串转数组,数组转字符串
string str = "1,2,3,4,5,6,7"; string[] strArray = str.Split(','); //字符串转数组 ...
- 权限获取异常(不能用ModuleId,得换个名字)目前还没搞清楚为啥
CenterController: /// <summary> /// 访问模块,写入系统菜单Id /// </summary> /// <param name=&quo ...
- Windows消息机制概述
消息是指什么? 消息系统对于一个win32程序来说十分重要,它是一个程序运行的动力源泉.一个消息,是系统定义的一个32位的值,他唯一的定义了一个事件,向 Windows发出一个通知,告诉应用程 ...
- JSTL函数
JSTL包含了一系列标准函数. 引入:<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functi ...
- php之XML转数组函数的方法
<?/** * xml2array() will convert the given XML text to an array in the XML structure. * Link: htt ...
- Temporary ASP.NET 拒绝访问
CS0016: 未能写入输出文件“c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\dd813f66 ...
- GnuPG 的PGP使用
1. 生成秘钥对(此处采用默认的RSA, 2048位) $ gpg --gen-key gpg (GnuPG) ; Copyright (C) Free Software Foundation, In ...
- Spark 1.1.0 编译(为了支持hbase 0.98.6)
为了支持hbase0.98.6,需要重新编译spark 1. 下载spark 1.1.0源代码,以及 scala-2.10.4的bin包. 将环境变量 SCALA_HOME 设置为 scala-2.1 ...