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

全部代碼:
<!DOCTYPE HTML>
<html>
<head>
<title>easydrag實(shí)現(xiàn)可拖動的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)行拖動</i></div>
<div class="content"><a ><img src="images/img03.jpg" /></a></div>
</div>
</div>
</body>
</html>
以上內(nèi)容是小編給大家介紹的使用jQuery的easydrag插件實(shí)現(xiàn)可拖動的DIV彈出框,希望對大家有所幫助!
- jQuery實(shí)現(xiàn)的鼠標(biāo)拖動浮層功能示例【拖動div等任何標(biāo)簽】
- jquery div拖動效果示例代碼
- jQuery拖動div、移動div、彈出層實(shí)現(xiàn)原理及示例
- jQuery實(shí)現(xiàn)單擊彈出Div層窗口效果(可關(guān)閉可拖動)
- jquery拖動改變div大小
- jquery實(shí)現(xiàn)可拖動DIV自定義保存到數(shù)據(jù)的實(shí)例
- jQuery實(shí)現(xiàn)Div拖動+鍵盤控制綜合效果的方法
- jQuery實(shí)現(xiàn)鼠標(biāo)拖動div改變位置、大小的實(shí)踐
相關(guān)文章
jquery實(shí)現(xiàn)點(diǎn)擊TreeView文本父節(jié)點(diǎn)展開/折疊子節(jié)點(diǎn)
今天客戶提出要點(diǎn)擊菜單(TreeView實(shí)現(xiàn)的)的父級節(jié)點(diǎn)時(shí),展開節(jié)點(diǎn),很多新手朋友可能對此會很陌生,接下來介紹解決方法,感興趣的朋友可以了解下2013-01-01
jquery實(shí)現(xiàn)上傳文件進(jìn)度條
這篇文章主要為大家詳細(xì)介紹了jquery實(shí)現(xiàn)上傳文件進(jìn)度條,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-03-03
總結(jié)jQuery插件開發(fā)中的一些要點(diǎn)
這篇文章主要介紹了總結(jié)jQuery插件開發(fā)中的一些要點(diǎn),包括命名空間與事件events等重點(diǎn)和難點(diǎn)部分的講解,要的朋友可以參考下2016-05-05
JQuery 動態(tài)生成Table表格實(shí)例代碼
這篇文章主要介紹了JQuery 動態(tài)生成Table表格實(shí)例代碼的相關(guān)資料,這里附有實(shí)現(xiàn)實(shí)例代碼,具有一定的參考價(jià)值,需要的朋友可以參考下2016-12-12
jquery簡單倒計(jì)時(shí)實(shí)現(xiàn)方法
這篇文章主要介紹了jquery簡單倒計(jì)時(shí)實(shí)現(xiàn)方法,涉及jQuery定時(shí)函數(shù)操作及日期與實(shí)現(xiàn)的運(yùn)算技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-12-12
jQuery實(shí)現(xiàn)原理的模擬代碼 -6 代碼下載
前幾篇文章中的示例代碼,去掉了幾個(gè) bug, 這里一起提供下載。2010-08-08

