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上,用于存放非主要信息 弹出框是依赖于工具提示插件的,那它也和工具提示是一样的,是需要初始化才能够使用的 首先我们引入 ...
随机推荐
- 解决SQLSERVER在还原数据时出现的“FILESTREAM功能被禁用”问题
解决SQLSERVER在还原数据时出现的“FILESTREAM功能被禁用”问题 今天由于测试需要,在网上下载了Adventureworks2008实例数据库的BAK文件,进行还原时出现了这样的错误“F ...
- dubbo源码分析2-reference bean发起服务方法调用
dubbo源码分析1-reference bean创建 dubbo源码分析2-reference bean发起服务方法调用 dubbo源码分析3-service bean的创建与发布 dubbo源码分 ...
- Python 字符串方法详解
Python 字符串方法详解 本文最初发表于赖勇浩(恋花蝶)的博客(http://blog.csdn.net/lanphaday),如蒙转载,敬请保留全文完整,切勿去除本声明和作者信息. ...
- MVC5关联表读取相关表数据
SchoolName = db.Sys_Company.Find(gr.SchoolCode).FullName 只需Model中指定好SchoolCode是Sys_Company的主键就行了!
- eclipse远程debug
由于一般比较正规项目,都会有好几个版本,有时候在测试版本的时候,一切都好好的,然后提交到其他版本之后会有各种各样的问题,这个时候如果不能快速准确的定位到问题,那么我们就需要用 eclipse远程deb ...
- 摸索js的3d全景
先我在网上找到了一个例子,http://silali.vicp.net/three/emaple.html 完美实现3d全景,在详细查看这个例子后,发现他在手机上运行并不流畅,而且显不全并会卡顿. 我 ...
- Bug测试报告--在线考试系统--金州勇士
项目名:在线考试系统 组名:金州勇士 测试者:宫丽君(nice!团队) 代码地址: ssh:git@git.coding.net:handsomeman/examm.git https://g ...
- Maven 使用介绍
1,创建Project 先去官方网站下载一个最新版本http://maven.apache.org/download.cgi. 下载后解压,使用之前最好先将maven的bin目录设置到path环境变量 ...
- nginx 设置 fastcgi缓存
#增加调试信息 add_header X-Cache-CFC "$upstream_cache_status - $upstream_response_time"; fastcgi ...
- ASP值view State
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...