我希望能够在Bootstrap 2中移动(在灰色背景下拖放)Bootstrap 2提供的模式窗体。任何人都可以告诉我实现此目的的最佳做法是什么?Twitter Bootstrap模态窗体:如何拖放?
回答
默认情况下,引导程序没有提供任何拖放功能,但您可以在混合中添加一些jQuery UI spice来获得您要查找的效果。例如,使用框架中的draggable
交互,您可以定位您的模式ID以允许它在模式背景中拖动。
试试这个:
JS
无论拖动选项你去,你可能要在引导的CSS文件关闭*-transition
属性.modal.fade
,或至少写一些JS说拖动过程中暂时禁用它们。否则,模式不会像您期望的那样完全拖动。
这个问题讨论和解决在http://stackoverflow.com/questions/15881245/draggable-js-bootstrap-modal-performance-issues – bbodenmiller
jquery的用户界面很大,可能会与bootstrap冲突。
另一种方法是DragDrop.js:http://kbjr.github.io/DragDrop/index.html
DragDrop.bind($('#myModal')[0], {
anchor: $('#myModal .modal-header')
});
你仍然必须处理的转变,如@ user535673建议。我只是从我的对话框中删除淡化类。
你可以使用一个小脚本来做这个。
(function ($) {
$.fn.drags = function (opt) {
opt = $.extend({
handle: "",
cursor: "move"
}, opt);
var $selected = this;
var $elements = (opt.handle === "") ? this : this.find(opt.handle);
$elements.css('cursor', opt.cursor).on("mousedown", function (e) {
var pos_y = $selected.offset().top - e.pageY,
pos_x = $selected.offset().left - e.pageX;
$(document).on("mousemove", function (e) {
$selected.offset({
top: e.pageY + pos_y,
left: e.pageX + pos_x
});
}).on("mouseup", function() {
$(this).off("mousemove"); // Unbind events from document
});
e.preventDefault(); // disable selection
});
return this;
};
})(jQuery);
例子被简化了:$( “#someDlg”)模态()拖动({手柄: “模态报头”})。。
您的代码已过时。尝试了你的代码,它的工作,但拖动是越野车。通过从上面的链接获取代码来修复它。请根据链接中的代码更新您的代码。 –
- 1. Twitter Bootstrap模态窗口
- 2. 制作Twitter Bootstrap模态窗口较大
- 3. Slick.js和多个Twitter Bootstrap模态窗口
- 4. Twitter Bootstrap模态窗口不显示
- 5. 拖放Windows窗体
- 6. Bootstrap:模态弹窗
- 7. 如何调试twitter bootstrap模态框?
- 8. 拖放弹出添加预填充的新模态窗体?
- 9. 模态内的Twitter Bootstrap模态?
- 10. Twitter Bootstrap模态,HTML或Javascript?
- 11. Twitter Bootstrap模态问题
- 12. Twitter Bootstrap模态幻灯片
- 13. 拖放Windows窗体按钮
- 14. 如果data-target =“#my-modal”放在Twitter Bootstrap的模态div中?
- 15. 使用Twitter Bootstrap的中心窗体
- 16. Twitter-Bootstrap和Rails中的窗体
- 17. Twitter-Bootstrap弹出窗口的动态放置
- 18. 如何在twitter bootstrap模式上将图像拖动到左侧?
- 19. Twitter Bootstrap 2.1模式正在删除模态主体内容
- 20. KnockoutJS/Bootstrap - 使用javascript关闭模态时清除模态窗体
- 21. twitter bootstrap:是窗体内部所需的窗体组类
- 22. 如何在窗体窗口上只拖放一个文件
- 23. Twitter BootStrap模式窗口后备链接
- 24. Twitter Bootstrap模式窗口闪烁
- 25. MS Access窗体上是否有任何拖放模块?
- 26. 如何在x-editable窗体中单击调用函数(Twitter Bootstrap)
- 27. 从模态窗体显示非模态窗体关闭模态窗体
- 28. 如何调整twitter bootstrap弹出窗口?
- 29. Twitter Bootstrap模态 - 灰色背景,但没有窗口
- 30. 如何将模板从twitter bootstrap v2.0迁移到twitter bootstrap v3.0
设置'.modal-header {cursor:move}'后,它就像魅力一样。 – DontVoteMeDown
我不能看到这个工作在最后一个引导版本,3.3.5。有小费吗?将Jquery更改为1.11.0,但没有运气。谢谢。 – Khrys
Hello @Khrys,这是一个带有可拖动模式标题的更新演示,http://output.jsbin.com/vafulubaju。这个答案很旧,所以我猜测演示中的一些JS链接被破坏了)。 –