jQuery 拖拽窗体
生活随笔
收集整理的這篇文章主要介紹了
jQuery 拖拽窗体
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
jQuery 拖拽窗體事件
今天給大家分享一個簡單拖拽事件,可以通過拖拽事件實現數據的傳遞,已達到良好的交互,可以實現更為可觀的效果。
具體來說,只有三部基本的操作:
第一:當鼠標按下時觸發的事件(onmousedown)。
第二:鼠標移動時事件(onmousemove)。
第三:鼠標松開時停止移動事件(onmouseup)。
首先,我們先設置樣式。
// 樣式<style>#XiaLa { background-image: url('../../Content/img/small.png');float: right;width: 18px;height: 18px;background-size: 100%;background-repeat: no-repeat;position: absolute;top: 3px;right: 18px;}#close_T {background-image: url('../../Content/img/close.PNG');width: 18px;height: 18px;background-size: 100%;background-repeat: no-repeat;position: absolute;top: 3px;right: 0px;}#Ha {width: 256px;position: absolute;top: 0%;left: 5%;background: #FFF;z-index: 2;border: 1px solid #3586D7;border-radius: 2px;display: none;}#Ha2 { width: 100%;height: 25px;line-height: 25px;text-align: center;background-color: #3586D7;position: relative; }.titleStyle{font-style: normal;color: #fff;font-size: 12px;font-weight: bold;font-family: "宋體";line-height: 22px !important;} </style>然后下面是body里面的代碼:
//<button class="btn btn-primary" type="button"onclick="fff()">點擊</button><div style="position: absolute;width:300px;width:220px;" id="Ha"><div id="Ha2"style="cursor: move;" >//cursor:定義了鼠標指針放在一個元素邊界范圍內時所用的光標形狀//move:此光標指示某對象可被移動。//pointer:光標呈現為指示鏈接的指針(一只手)<i class="titleStyle">魔鬼</i><i style="cursor: pointer;" id="XiaLa" ></i><i style="cursor: pointer;" id="close_T" onclick="closeDialog_T()" ></i></div><div id="NeiRong"> </div> </div>這是css里面的屬性值,方便大家參考:
接下來就是要寫方法,然后觸發拖拽事件:
所上代碼所示,也有注釋分析,一個簡單的拖拽就這樣完成了。
//這里是窗體向下與向上點擊事件的判斷 var TF = true;$("#XiaLa").click(function () {if (TF) {$("#NeiRong").attr("style", "display:block;width:214px;height:212px;border:3px solid #3586D;");TF = false;} else {$("#NeiRong").attr("style", "display:none");TF = true;}});實現的效果圖如下,圖中的藍色導航部分當鼠標選中并進行拖拽時,改變背景顏色,背景顏色透明顯示,點擊:
總結
以上是生活随笔為你收集整理的jQuery 拖拽窗体的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android开发中调用Spring C
- 下一篇: Collection集合总结