Draggable JS Bootstrap modal - performance issues(Draggable JS Bootstrap modal - 性能问题)
问题描述
对于工作中的项目,我们使用 JavaScript 中的 Bootstrap 模态窗口.我们想让一些窗口可以移动,但是我们遇到了 JQuery 的性能问题.
For a project at work we use Bootstrap Modal windows in JavaScript. We would like to make some of the windows movable, but we are running into performance issues with JQuery.
$("#myModal").draggable({
handle: ".modal-header"
});
示例 ,
来源 .
在 IE9 中,它按预期工作.
在 Chrome 中,水平拖动按预期工作,垂直拖动相当慢但没有问题.
在 Firefox 中,水平拖动按预期工作,但垂直拖动非常慢.
Example ,
Source .
In IE9, it works as expected.
In Chrome, horizontal dragging works as expected, and vertical dragging is rather slow but not problematic.
In Firefox, horizontal dragging works as expected, but vertical dragging is extremely slow.
这很奇怪,因为示例窗口在图形上并不繁重,而且 JQuery 应该规范浏览器行为.我尝试不使用 JQuery 的可拖动来解决这个问题,但我遇到了同样的问题.
It's strange, because the example window is not graphically heavy and JQuery is supposed to normalize browser behavior. I tried solving this without using JQuery's draggable, but I ran into the same issue.
所以我有几个问题:
- 性能缓慢是浏览器、JQuery、Bootstrap 的问题还是我的代码不是最优的?
- 为什么水平和垂直拖动有区别?
- 我应该找到一种解决方法,还是完全避免使用 Bootstrap 来处理动态弹出窗口?
亲切的问候,圭多
推荐答案
我找到了一些方法来解决这个问题.
I found a few ways to fix this.
将此添加到您的 CSS 文件将在拖动模态时禁用 transition 效果.然而,似乎一旦用户拖动框,飞入将不会正确发生,而是会淡入.
Adding this to your CSS file will disable the transition effects while the modal is being dragged. It appears however that once the user drags the box the fly in will not occur correctly but rather it will just fade in.
.modal.fade.ui-draggable-dragging {
-moz-transition: none;
-o-transition: none;
-webkit-transition: none;
transition: none;
}
或者将以下内容添加到您的 CSS 文件和 nofly 类到您的模型将一起禁用飞入,但不会淡入:
Alternatively adding the following to your CSS file and the nofly class to your model will disable the fly in all together but not the fade in:
.modal.fade.nofly {
top: 10%;
-webkit-transition: opacity 0.3s linear;
-moz-transition: opacity 0.3s linear;
-o-transition: opacity 0.3s linear;
transition: opacity 0.3s linear;
}
这篇关于Draggable JS Bootstrap modal - 性能问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Draggable JS Bootstrap modal - 性能问题
基础教程推荐
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
