动画过程中位置不正确
Improper position during animation
我有两个使用Jquery拖放的可交换div。
当我尝试使用拖动来交换div 时,动画期间div 的位置是不合适的。div 的交换正在正常进行,但问题出在动画期间。
.HTML
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal" id="toz">Open Modal</button>
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<div class='droppable'>
<div class="draggable">Draggable 1</div>
</div>
<div class='droppable'>
<div class="draggable">Draggable 2</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
JavaScript
$(document).ready(function() {
window.startPos = window.endPos = {};
makeDraggable();
$('.droppable').droppable({
hoverClass: 'hoverClass',
drop: function(event, ui) {
var $from = $(ui.draggable),
$fromParent = $from.parent(),
$to = $(this).children(),
$toParent = $(this);
window.endPos = $to.offset();
swap($from, $from.offset(), window.endPos, 200);
swap($to, window.endPos, window.startPos, 1000, function() {
$toParent.html($from.css({
position: 'relative',
left: '',
top: '',
'z-index': ''
}));
$fromParent.html($to.css({
position: 'relative',
left: '',
top: '',
'z-index': ''
}));
makeDraggable();
});
}
});
function makeDraggable() {
$('.draggable').draggable({
zIndex: 99999,
revert: 'invalid',
start: function(event, ui) {
window.startPos = $(this).offset();
}
});
}
function swap($el, fromPos, toPos, duration, callback) {
$el.css('position', 'absolute')
.css(fromPos)
.animate(toPos, duration, function() {
if (callback) callback();
});
}
});
问题的小提琴演示
只需将绝对更改为固定工作。小提琴
function swap($el, fromPos, toPos, duration, callback) {
$el.css('position', 'fixed')
.css(fromPos)
.animate(toPos, duration, function() {
if (callback) callback();
});
}
相关文章:
- DIV并排,位置不正确
- 在页面中找不到元素的正确位置.函数未考虑填充
- 将CSS应用于在JavaScript中创建的表-表的位置不正确
- 谷歌地图标记IE中的位置不正确,在chrome上工作正常
- 按钮在 Chrome 中的位置不正确
- 动画过程中位置不正确
- 超时后,图像不会重新出现在其正确位置
- 从 SVG 加载的结构 JS 形状的位置不正确
- 使用 jQuery 滑块缩放图像的位置不正确
- 为什么这些列表项的位置不正确
- Phonegap:在目录中导航,索引位置不正确
- Div不是't处于正确位置
- Jquery日期选择器图标位置不正确
- 使用jQuery Mobile构建的iOS应用程序的页脚位置不正确
- 使用VS Code、TypeScript和Node.js的断点位置不正确
- 道场堆叠条形/柱形图表标签位置不正确
- 打印时绝对定位元素的位置不正确
- Html5画布绘制位置不正确
- 刷新页面后图像位置不正确
- 和中逗号的位置不正确