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

全部代碼:
<!DOCTYPE HTML>
<html>
<head>
<title>easydrag實現(xiàn)可拖動的DIV彈出框</title>
<style>
/* 重置瀏覽器默認樣式 */
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>點擊標題位置進行拖動</i></div>
<div class="content"><a ><img src="images/img03.jpg" /></a></div>
</div>
</div>
</body>
</html>
以上內(nèi)容是小編給大家介紹的使用jQuery的easydrag插件實現(xiàn)可拖動的DIV彈出框,希望對大家有所幫助!
相關(guān)文章
jQuery中的ready函數(shù)與window.onload誰先執(zhí)行
這篇文章主要介紹了jquery中ready函數(shù)與window.onload函數(shù)的區(qū)別,別講解了他們各自執(zhí)行的時機,通俗易懂,需要的朋友可以參考下。2016-06-06
jQuery+ajax實現(xiàn)動態(tài)添加表格tr td功能示例
這篇文章主要介紹了jQuery+ajax實現(xiàn)動態(tài)添加表格tr td功能,結(jié)合實例形式分析了jQuery基于ajax動態(tài)創(chuàng)建頁面table元素相關(guān)操作技巧,需要的朋友可以參考下2018-04-04
jQuery實現(xiàn)為動態(tài)添加的元素綁定事件實例分析
這篇文章主要介紹了jQuery實現(xiàn)為動態(tài)添加的元素綁定事件,結(jié)合實例形式分析了jQuery常見的事件綁定相關(guān)操作技巧與注意事項,需要的朋友可以參考下2018-09-09
jquery3和layui沖突導(dǎo)致使用layui.layer.full彈出全屏iframe窗口時高度152px問題
這篇文章主要介紹了解決jquery3和layui沖突導(dǎo)致使用layui.layer.full彈出全屏iframe窗口時高度152px問題,需要的朋友可以參考下2019-05-05
jquery得到font-size屬性值實現(xiàn)代碼
font-size屬性想必大家并不陌生吧,此屬性控制字體的大小,在本文將為大家介紹下如何使用jquery獲取font-size屬性值,感興趣的朋友可以參考下2013-09-09

