javascript移动ModalDialog

var i=0;
var intervalID=0;
function intervalstart(){
    intervalID=window.setInterval("movedlg()",300);  
}
function movedlg(){
    i=i+1;
    if(i>=5){
        window.clearInterval(intervalID);  
    }
    var top=260-i*10;
    window.dialogTop=top;

}

是的,Bootstrap Modal 可以通过添加一些 JavaScript 代码来实现可移动。可以使用 jQuery UI 中的 `draggable()` 方法,或者手动实现移动事件。以下是手动实现的示例代码: 在 Modal 打开后添加以下 JavaScript 代码: ```javascript var modalHeader = document.querySelector('.modal-header'); var modalDialog = document.querySelector('.modal-dialog'); var mouseStart = { x: 0, y: 0 }; var modalStart = { x: 0, y: 0 }; modalHeader.addEventListener('mousedown', function(e) { mouseStart.x = e.clientX; mouseStart.y = e.clientY; modalStart.x = parseInt(window.getComputedStyle(modalDialog).left); modalStart.y = parseInt(window.getComputedStyle(modalDialog).top); document.addEventListener('mousemove', moveModal); document.addEventListener('mouseup', stopMoveModal); }); function moveModal(e) { var deltaX = e.clientX - mouseStart.x; var deltaY = e.clientY - mouseStart.y; modalDialog.style.left = modalStart.x + deltaX + 'px'; modalDialog.style.top = modalStart.y + deltaY + 'px'; } function stopMoveModal() { document.removeEventListener('mousemove', moveModal); document.removeEventListener('mouseup', stopMoveModal); } ``` 这段代码将 Modal 头部作为可拖动的区域,当鼠标按下时,记录鼠标和 Modal 的初始位置,并添加移动事件。移动事件中计算鼠标位移量,并更新 Modal 的位置。鼠标松开时,移除移动事件。 需要注意的是,这种实现方式可能会与 Modal 的一些功能产生冲突,比如 Modal 中的表单输入框可能会触发移动事件。因此,在实际使用中需要针对具体情况进行调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值