jQuery實(shí)現(xiàn)的簡(jiǎn)單對(duì)話(huà)框拖動(dòng)功能示例
本文實(shí)例講述了jQuery實(shí)現(xiàn)的簡(jiǎn)單對(duì)話(huà)框拖動(dòng)功能。分享給大家供大家參考,具體如下:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title>www.dbjr.com.cn jquery 拖動(dòng)</title> <meta name="description" content=""> <meta name="keywords" content=""> <link href="" rel=" rel="external nofollow" stylesheet"> <style> *{margin: 0;padding: 0;box-sizing: border-box;-moz-user-select:none;} body {font: 12px/16px bold 'microsoft yahei,微軟雅黑';} .dragContainer { width: 382px; height: 395px; position: absolute; top: 50%; left: 50%; border: 1px solid red; margin-left: -191px; margin-top: -197.5px; } .dragContainer .dragtitle { width: 100%; height: 35px; border-bottom: 1px solid red; text-align: center; line-height: 35px; } .dragContainer .dragtitle:hover { cursor: move; } .dragContainer .content { width: 100%; height: 360px; } p.buttonGroup { width: 100%; text-align: center; position: absolute; bottom: 0; left: 0; right: 0; padding: 5px; border-top: 1px solid red; } p.buttonGroup input { padding: 5px 10px; color: white; } p.buttonGroup input:hover { cursor: pointer; cursor: hand; } p.buttonGroup input:first-child { margin-left: 25px; background: blue; } p.buttonGroup input.btn2 { margin-left: 15px; background: red; } </style> </head> <body> <div class="dragContainer" id="drag" style="'position:absolute;" > <p class="dragtitle">標(biāo)題欄</p> <div class="content"></div> <p class="buttonGroup"><input type="button" value="確定"><input type="button" value="取消" class="btn2"></p> </div> <script src="http://cdn.bootcss.com/jquery/2.1.0/jquery.js"></script> <script type="text/javascript"> var mydrag={ mousePoint: {x:0,y:0}, //初始化坐標(biāo) drag: function(){ var that=this; //保存當(dāng)前對(duì)象即(mydrag),如果不保存,在mousedown()里訪(fǎng)問(wèn)不了mydrag這個(gè)對(duì)象 var targetid=$(".dragtitle"); targetid.mousedown(function(event){ var e=event; var offsetLeft=targetid.offset().left; //當(dāng)前div的左偏移距離 var offsetTop=targetid.offset().top; //當(dāng)前div的頂部偏移距離 that.mousePoint.x=e.clientX-offsetLeft;//計(jì)算鼠標(biāo)點(diǎn)擊時(shí)離它自己div的橫向距離 that.mousePoint.y=e.clientY-offsetTop; //計(jì)算鼠標(biāo)點(diǎn)擊時(shí)離它自己div的縱向距離 $(document).bind('mousemove',move); e.stopPropagation(); }); function move(event){ var e =event; var Left=e.clientX-that.mousePoint.x; //移動(dòng)后,重新計(jì)算左偏移和頂部偏移距離 var Top=e.clientY-that.mousePoint.y; $("#drag").css({'top':Top,'left':Left,'margin':0}); $(document).bind('mouseup',end); e.stopPropagation(); }; function end(event){ var e = event; $(document).unbind('mousemove', move); $(document).unbind('mouseup',end); e.stopPropagation(); }; } } mydrag.drag(); </script> </body> </html>
使用在線(xiàn)HTML/CSS/JavaScript代碼運(yùn)行工具 http://tools.jb51.net/code/HtmlJsRun測(cè)試,運(yùn)行效果如下:
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《jQuery拖拽特效與技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jquery中Ajax用法總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常見(jiàn)經(jīng)典特效匯總》、《jQuery動(dòng)畫(huà)與特效用法總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
- jquery實(shí)現(xiàn)表格行拖動(dòng)排序
- jQuery-ui插件sortable實(shí)現(xiàn)自由拖動(dòng)排序
- 針對(duì)后臺(tái)列表table拖拽比較實(shí)用的jquery拖動(dòng)排序
- jQuery拖動(dòng)元素并對(duì)元素進(jìn)行重新排序
- jQuery仿360導(dǎo)航頁(yè)圖標(biāo)拖動(dòng)排序效果代碼分享
- jquery實(shí)現(xiàn)的鼠標(biāo)拖動(dòng)排序Li或Table
- jquery對(duì)元素拖動(dòng)排序示例
- 基于JQuery的列表拖動(dòng)排序?qū)崿F(xiàn)代碼
- jQuery實(shí)現(xiàn)移動(dòng)端懸浮拖動(dòng)效果
- jquery+css實(shí)現(xiàn)移動(dòng)端元素拖動(dòng)排序
相關(guān)文章
MultiSelect左右選擇控件的設(shè)計(jì)與實(shí)現(xiàn)介紹
由于項(xiàng)目中用到左右選擇的控件,網(wǎng)上找了一些相關(guān)的實(shí)現(xiàn),基本上有兩個(gè):1、基于JQuery UI的控件2、某個(gè)兄弟手寫(xiě)的一個(gè)控件,具體實(shí)現(xiàn)如下,感興趣的朋友可以參考下哈2013-06-06Lazy Load 延遲加載圖片的jQuery插件中文使用文檔
Lazy Load 是一個(gè)用 JavaScript 編寫(xiě)的 jQuery 插件. 它可以延遲加載長(zhǎng)頁(yè)面中的圖片. 在瀏覽器可視區(qū)域外的圖片不會(huì)被載入, 直到用戶(hù)將頁(yè)面滾動(dòng)到它們所在的位置. 這與圖片預(yù)加載的處理方式正好是相反的2012-10-10JQuery擴(kuò)展插件Validate—6 radio、checkbox、select的驗(yàn)證
radio、checkbox、select的驗(yàn)證其實(shí)方法與前面提到?jīng)]有太大的區(qū)別,但問(wèn)題是錯(cuò)誤信息會(huì)顯示在同一組的第一個(gè)元素后面2011-09-09Jquery easyui開(kāi)啟行編輯模式增刪改操作
jquery easyui框架提供了創(chuàng)建網(wǎng)頁(yè)所需要的一切,可以幫助大家建立站點(diǎn),接下來(lái),通過(guò)本文給大家介紹Jquery easyui開(kāi)啟行編輯模式增刪改操作,感興趣的朋友一起學(xué)習(xí)2016-01-01jquery 簡(jiǎn)單圖片導(dǎo)航插件jquery.imgNav.js
前幾天某MM要偶幫忙實(shí)現(xiàn)栗子汀首頁(yè)的圖片導(dǎo)航效果,很簡(jiǎn)單而且具有通用性的一個(gè)需求,點(diǎn)圖片A切換圖片A相關(guān)的內(nèi)容,點(diǎn)圖片B切換圖片B相關(guān)的內(nèi)容,僅此而已。2010-03-03jQuery實(shí)現(xiàn)的一個(gè)自定義Placeholder屬性插件
這篇文章主要介紹了jQuery實(shí)現(xiàn)的一個(gè)自定義Placeholder屬性插件,本文最后附有插件完整源碼,需要的朋友可以參考下2014-08-08jQuery UI實(shí)現(xiàn)動(dòng)畫(huà)效果代碼分享
這篇文章給大家總結(jié)了jQuery UI實(shí)現(xiàn)動(dòng)畫(huà)效果的實(shí)例代碼,有需要的朋友們可以參考測(cè)試下。2018-08-08jquery.validate表單驗(yàn)證插件使用詳解
這篇文章主要為大家詳細(xì)介紹了jquery.validate表單驗(yàn)證插件的使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06