2 ,拖动

1 ,拖动 : 简单实现

  1. html 部分 :
<div id="box" style="height: 100px;width: 100px;background-color: orange"></div>
  1. js 部分 :
$(function(){
    $("#box").draggable()
});
  1. 结果 : 可以拖着走了

2 ,只能拖住一部分 ( 例如只能拖住标题 )

  1. 代码 :
$("#box").draggable({
    handle:"#content"
})
<div id="box" style="height: 100px;width: 100px;background-color: orange">
    <spanid="content">内容区域</span>
</div>
  1. 效果 :
    想拖走,可以,但是必须拖着我的头走,不能拖着我的脚走

3 ,拖动结束触发方法 :

$("#box").draggable({
    handle:"#content",
    onStopDrag:function (e) {
        alert("拖动结束...")
    }
})

4 ,不可以拖动:

$("#box").draggable("disable")

5 ,可以拖动 :

$("#box").draggable("enable")

6 ,获取属性值 :

$("#box").draggable()
alert($("#box").draggable("options"))
发布了472 篇原创文章 · 获赞 25 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/qq_34319644/article/details/104150528