jquery-ui实现bootstrap的modal拖拽功能,弹窗头部拖拽

首先我做的bootstrap的拖拽功能是靠插件jquery-ui实现的,所以使用前必须要先在jquery.js之后引入JS,

大概是这样的顺序

<link href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.css" rel="stylesheet">
<script src="//cdn.bootcss.com/jquery/2.1.4/jquery.js"></script>
<script src="//cdn.bootcss.com/jqueryui/1.11.4/jquery-ui.js"></script> // 完成拖拽功能
<script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.js"></script> // 完成Modal
在JS中的绑定方法
$(".modal").each(function(){
    $(this).draggable({
        handle: ".modal-header"   // 只能点击头部拖动
    });
    $(this).css("overflow", "hidden"); // 防止出现滚动条,出现的话,你会把滚动条一起拖着走的
});

也可以绑定在弹出事件上

$(document).on("show.bs.modal", ".modal", function(){
    $(this).draggable();
    //直接这样写,点击整个弹窗的任意部位都能拖动
});

bootstrap modal 的四个常用事件:

事件描述示例
show.bs.modal在调用 show 方法后触发。 $("#identifier").on('show.bs.modal', function(){//do sth. });
show.bs.modal当模态框对用户可见时触发(将等待 CSS 过渡效果完成)。 $("#identifier").on('shown.bs.modal', function(){//do sth. });
hide.bs.modal当调用 hide 方法时触发。 $("#identifier").on('hide.bs.modal', function(){//do sth. });
hidden.bs.modal当模态框完全对用户隐藏时触发。 $("#identifier").on('hidden.bs.modal', function(){//do sth. });
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值