欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery簡(jiǎn)單的拖動(dòng)效果實(shí)現(xiàn)原理及示例

 更新時(shí)間:2013年07月26日 17:35:16   作者:  
本文為大家詳細(xì)介紹下jQuery拖曵的簡(jiǎn)單實(shí)例,具體的實(shí)現(xiàn)思路及代碼如下,感興趣的朋友可以參考下哈,希望對(duì)大家有所幫助
復(fù)制代碼 代碼如下:

<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>簡(jiǎn)單拖曵原理實(shí)例</title>
<style type="text/css">
#drag{width:400px;height:300px;background:url(http://upload.yxgz.cn/uploadfile/2009/0513/20090513052611873.jpg);cursor:move;position:absolute;top:100px;left:100px;border:solid 1px #ccc;}
h2{color:#fff;background: none repeat scroll 0 0 rgba(16, 90, 31, 0.7);color:#FFFFFF;height:40px;line-height:40px;margin:0;}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
/*--------------拖曳效果----------------
*原理:標(biāo)記拖曳狀態(tài)dragging ,坐標(biāo)位置iX, iY
* mousedown:fn(){dragging = true, 記錄起始坐標(biāo)位置,設(shè)置鼠標(biāo)捕獲}
* mouseover:fn(){判斷如果dragging = true, 則當(dāng)前坐標(biāo)位置 - 記錄起始坐標(biāo)位置,絕對(duì)定位的元素獲得差值}
* mouseup:fn(){dragging = false, 釋放鼠標(biāo)捕獲,防止冒泡}
*/
var dragging = false;
var iX, iY;
$("#drag").mousedown(function(e) {
dragging = true;
iX = e.clientX - this.offsetLeft;
iY = e.clientY - this.offsetTop;
this.setCapture && this.setCapture();
return false;
});
document.onmousemove = function(e) {
if (dragging) {
var e = e || window.event;
var oX = e.clientX - iX;
var oY = e.clientY - iY;
$("#drag").css({"left":oX + "px", "top":oY + "px"});
return false;
}
};
$(document).mouseup(function(e) {
dragging = false;
$("#drag")[0].releaseCapture();
e.cancelBubble = true;
})

})

</script>
</head>

<body>
<div id="drag">
<h2>來拖動(dòng)我啊</h2>
</div>
</body>
</html>

相關(guān)文章

最新評(píng)論