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上,用于存放非主要信息 弹出框是依赖于工具提示插件的,那它也和工具提示是一样的,是需要初始化才能够使用的 首先我们引入 ...
随机推荐
- 一种在视频OBJECT标签上放置均分四个区域的框选方法
一般在视频区域中做框样式,作应由视频插件自己来实现,但是出于其它一些原因自己琢磨了一个使用HTML标签来实现框选区域的方法,按照行外应该属于笨方法,虽然有点笨,可能在其他方面有借鉴意义,在这里拿出来跟 ...
- lua 环境揭秘
什么是环境? http://www.lua.org/manual/5.1/manual.html#2.9 Besides metatables, objects of types thread, fu ...
- .Net分布式架构(二):基于Redis的Session共享
一:Session简介 Session是什么呢?简单来说就是服务器给客户端的一个编号.当一台web服务器运行时,可能有若干个用户浏览正在运正在这台服务器上的网站.当每个用户首次与这台web服务器建立连 ...
- Adobe CS6 全系列官方下载地址 (迅雷无效) Win Mac
https://helpx.adobe.com/x-productkb/policy-pricing/cs6-product-downloads.html CS6 Design & Web P ...
- SQLDMO知识总结
SQLDMO(SQL Distributed Management Objects) 参考手册:http://technet.microsoft.com/en-us/library/aa312550( ...
- datatable-提示
`默认columns配置问题: 记住是columnDefs不是columnsDefs `Cannot read property 'sWidth' of undefined: columns的数量和t ...
- Ugly Number II
注意负数,所以要使用long,而不能用int 详细解释 请参见http://www.cnblogs.com/julie-yang/p/5147460.html #include<vector&g ...
- Java菜鸟培训第二天
HTML——超文本标记语言…………… 静态网页:不需要访问数据库. 动态网页:在网上发布的好的,我们能通过网络浏览到的都是动态的,需要访问数据库. <html>--开始标签 <hea ...
- 浙江理工2015.12校赛-F Landlocked
Landlocked Time Limit: 5 Sec Memory Limit: 128 MB Submit: 288 Solved: 39 Description Canada is not a ...
- jenkins对结果进行断言问题
TextFinder plugin插件 Jenkins在判定使用shell scripts完成build成功与否的时候,是根据shell最终的返回值是否为零来判定的:零即成功,非零即失败.这点判定事实 ...