使用jQuery的easydrag插件實(shí)現(xiàn)可拖動(dòng)的DIV彈出框
EasyDrag 是一個(gè)用來實(shí)現(xiàn)頁(yè)面元素拖拉的 jQuery 插件。
在沒遇到easydrag插件之前,想實(shí)現(xiàn)一個(gè)彈出框并不是一件輕而易舉的事情!
人們常說沒有不勞而獲的事情,但在編碼的世界中卻不是這樣。更多的開源框架方面了我們,也毒害了我們!
廢話少說,先看效果:

全部代碼:
<!DOCTYPE HTML>
<html>
<head>
<title>easydrag實(shí)現(xiàn)可拖動(dòng)的DIV彈出框</title>
<style>
/* 重置瀏覽器默認(rèn)樣式 */
body,h1,h2,h3,h4,h5,h6,p,ul,ol,li,form,img,dl,dt,dd,table,th,td,blockquote,fieldset,div,strong,label,em{margin:0;padding:0;border:0;}
ul,ol,li{list-style:none;}
input,button{margin:0;font-size:12px;vertical-align:middle;}
body{font-size:12px;font-family:Arial, Helvetica, sans-serif; color:#333; margin:0 auto; }
table{border-collapse:collapse;border-spacing:0;}
a{ color:#333; text-decoration:none;}
a:hover{ text-decoration:none;}
.wrap{ width:960px; margin:20px auto;}
.box{ display:none; background:#fff; border:1px solid #ccc; position:absolute;}
#popbox{ width:550px;height:320px;overflow:hidden;}
#handler{ width:98%; height:30px; line-height:30px; overflow:hidden; color:#fff; border-bottom:1px solid #ccc; background:#ccc; padding-left:2%; float:left;}
.btn{ display:block; width:90px; height:28px; border:1px solid #ccc; line-height:28px; text-align:center; margin-right:20px; float:left; display:inline; margin-right:15px; cursor:pointer;}
.close{ display:block; background:url(images/close.gif) no-repeat; width:13px; height:13px; float:right; text-indent:-999em; cursor:pointer; display:inline; margin:8px 12px 0 0;}
.head i{ float:left; font-style:normal;}
.content{ width:100%; float:left;}
.content img{width:100%;}
</style>
<!-- 使用百度的jquery在線cdn -->
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<!-- easydrag.js沒有找到在線的cdn,大家可以自行下載 -->
<script type="text/javascript" src="js/easydrag.js"></script>
<script language="javascript">
$(function(){
//btn綁定click事件
$('.btn').click(function(){
//設(shè)置彈出框居中
$('#popbox').css({
left: ($(window).width() - $('#popbox').outerWidth())/2,
top: ($(window).height() - $('#popbox').outerHeight())/2 + $(document).scrollTop()
});
$('#popbox').easydrag();
//淡入已隱藏的div
$('#popbox').fadeIn();
$('#popbox').setHandler('handler');
$('.close').click(function(){
//淡出效果來隱藏彈出的div
$('#popbox').fadeOut();
});
});
});
</script>
</head>
<body>
<div class="wrap">
<b class="btn">打開彈出框</b>
<div id="popbox" class="box">
<div class="head" id="handler"><b class="close">關(guān)閉</b><i>點(diǎn)擊標(biāo)題位置進(jìn)行拖動(dòng)</i></div>
<div class="content"><a ><img src="images/img03.jpg" /></a></div>
</div>
</div>
</body>
</html>
以上內(nèi)容是小編給大家介紹的使用jQuery的easydrag插件實(shí)現(xiàn)可拖動(dòng)的DIV彈出框,希望對(duì)大家有所幫助!
- jQuery實(shí)現(xiàn)的鼠標(biāo)拖動(dòng)浮層功能示例【拖動(dòng)div等任何標(biāo)簽】
- jquery div拖動(dòng)效果示例代碼
- jQuery拖動(dòng)div、移動(dòng)div、彈出層實(shí)現(xiàn)原理及示例
- jQuery實(shí)現(xiàn)單擊彈出Div層窗口效果(可關(guān)閉可拖動(dòng))
- jquery拖動(dòng)改變div大小
- jquery實(shí)現(xiàn)可拖動(dòng)DIV自定義保存到數(shù)據(jù)的實(shí)例
- jQuery實(shí)現(xiàn)Div拖動(dòng)+鍵盤控制綜合效果的方法
- jQuery實(shí)現(xiàn)鼠標(biāo)拖動(dòng)div改變位置、大小的實(shí)踐
相關(guān)文章
jQuery中的ready函數(shù)與window.onload誰(shuí)先執(zhí)行
這篇文章主要介紹了jquery中ready函數(shù)與window.onload函數(shù)的區(qū)別,別講解了他們各自執(zhí)行的時(shí)機(jī),通俗易懂,需要的朋友可以參考下。2016-06-06
jQuery+ajax實(shí)現(xiàn)動(dòng)態(tài)添加表格tr td功能示例
這篇文章主要介紹了jQuery+ajax實(shí)現(xiàn)動(dòng)態(tài)添加表格tr td功能,結(jié)合實(shí)例形式分析了jQuery基于ajax動(dòng)態(tài)創(chuàng)建頁(yè)面table元素相關(guān)操作技巧,需要的朋友可以參考下2018-04-04
jQuery表格插件ParamQuery簡(jiǎn)單使用方法示例
這篇文章主要介紹了jQuery表格插件ParamQuery簡(jiǎn)單使用方法示例,大家參考使用吧2013-12-12
jQuery實(shí)現(xiàn)為動(dòng)態(tài)添加的元素綁定事件實(shí)例分析
這篇文章主要介紹了jQuery實(shí)現(xiàn)為動(dòng)態(tài)添加的元素綁定事件,結(jié)合實(shí)例形式分析了jQuery常見的事件綁定相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下2018-09-09
jquery拖動(dòng)插件(jquery.drag)使用介紹
可以使用鼠標(biāo)任意拖動(dòng)列表項(xiàng)改變默認(rèn)的位置,具體的實(shí)現(xiàn)如下(附演示),感興趣的朋友可以學(xué)習(xí)下2013-06-06
jquery3和layui沖突導(dǎo)致使用layui.layer.full彈出全屏iframe窗口時(shí)高度152px問題
這篇文章主要介紹了解決jquery3和layui沖突導(dǎo)致使用layui.layer.full彈出全屏iframe窗口時(shí)高度152px問題,需要的朋友可以參考下2019-05-05
jquery得到font-size屬性值實(shí)現(xiàn)代碼
font-size屬性想必大家并不陌生吧,此屬性控制字體的大小,在本文將為大家介紹下如何使用jquery獲取font-size屬性值,感興趣的朋友可以參考下2013-09-09
前端分頁(yè)功能的實(shí)現(xiàn)以及原理(jQuery)
本文主要介紹了基于jQuery實(shí)現(xiàn)的前端分頁(yè)功能,并分析了其實(shí)現(xiàn)原理。具有很好的參考價(jià)值,下面跟著小編一起來看下吧2017-01-01

