熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

jquery簡單的拖動效果實現原理及示例

2022-06-13   來源: JSP教程 
本文為大家詳細介紹下jQuery拖曵的簡單實例具體的實現思路及代碼如下感興趣的朋友可以參考下哈希望對大家有所幫助   復制代碼 代碼如下:

  
<!DOCTYPE html>
<html>
<meta httpequiv="ContentType" content="text/html; charset=utf" />
<title>簡單拖曵原理實例</title>
<style type="text/css">
#drag{width:px;height:px;background:url:move;position:absolute;top:px;left:px;border:solid px #ccc;}
h{color:#fff;background: none repeat scroll rgba( );color:#FFFFFF;height:px;lineheight:px;margin:;}
</style>
<script src="
<script type="text/javascript">
$(function(){
/*拖曳效果
*原理標記拖曳狀態dragging 坐標位置iX iY
* mousedown:fn(){dragging = true 記錄起始坐標位置設置鼠標捕獲}
* mouseover:fn(){判斷如果dragging = true 則當前坐標位置 記錄起始坐標位置絕對定位的元素獲得差值}
* mouseup:fn(){dragging = false 釋放鼠標捕獲防止冒泡}
*/
var dragging = false;
var iX iY;
$("#drag")mousedown(function(e) {
dragging = true;
iX = eclientX thisoffsetLeft;
iY = eclientY thisoffsetTop;
thissetCapture && thissetCapture();
return false;
});
documentonmousemove = function(e) {
if (dragging) {
var e = e || windowevent;
var oX = eclientX iX;
var oY = eclientY iY;
$("#drag")css({"left":oX + "px" "top":oY + "px"});
return false;
}
};
$(document)mouseup(function(e) {
dragging = false;
$("#drag")[]releaseCapture();
ecancelBubble = true;
})

})

</script>
</head>

<body>
<div id="drag">
<h>來拖動我啊</h>
</div>
</body>
</html>


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20094.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.