亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

jQuery 版元素拖拽原型代碼

 更新時間:2011年04月25日 01:17:42   作者:  
“元素拖拽”顧名思義:拖動,移動,拽放。有很多的解釋,而且在網(wǎng)上相關資料非常之多,本人在開發(fā) AsyncBox 當中也用到此效果,借此分享,同時也是一種技術積累。
本文主要針對拖拽原型進行解析,給剛接觸 JQuery 的愛好者一個簡單的示例。
在引入 Jquery.js 后:
復制代碼 代碼如下:

<script type="text/javascript">
$(function(){
//綁定拖動元素對象
bindDrag(document.getElementById('test'));
});
function bindDrag(el){
//初始化參數(shù)
var els = el.style,
//鼠標的 X 和 Y 軸坐標
x = y = 0;
//邪惡的食指
$(el).mousedown(function(e){
//按下元素后,計算當前鼠標位置
x = e.clientX - el.offsetLeft;
y = e.clientY - el.offsetTop;
//IE下捕捉焦點
el.setCapture && el.setCapture();
//綁定事件
$(document).bind('mousemove',mouseMove).bind('mouseup',mouseUp);
});
//移動事件
function mouseMove(e){
//宇宙超級無敵運算中...
els.top = e.clientY - y + 'px';
els.left = e.clientX - x + 'px';
}
//停止事件
function mouseUp(){
//IE下釋放焦點
el.releaseCapture && el.releaseCapture();
//卸載事件
$(document).unbind('mousemove',mouseMove).unbind('mouseup',mouseUp);
}
}
</script>

下載:完整示例

相關文章

最新評論