jQuery可拖动改变图像大小在拖动开始,恢复原来的大小在恢复
jQuery draggable change image size on drag start, restore original size on revert
我有一组不同大小的div
,具有相同的.gjg-item
类。我有它,所以你可以拖放这些div
到彼此的位置。
我怎么能告诉jquery不仅缩小图像在dragstart
但恢复到它的原始大小在revert
上?
$('.gjg-item').draggable({snap: true, snapMode: 'inner', revert: 'invalid'});
$('.gjg-item').droppable({accept: '.gjg-item', hoverClass: "ui-state-hover"});
$('.gjg-item').on('dragstart', function(event, ui) {
$(this).css('z-index', '9999999').width(50).height(50);
$(this).find('img').width(50).height(50);
});
$('.gjg-item').on("dropover", function(event, ui){
var draggingImgID = ui.draggable[0].id;
var hoverPositionSize = $(this).width();
if($(this).attr('data-pid') != draggingImgID) {
$(this).css('opacity', '.2');
}
});
$('.gjg-item').on("dropout", function(event, ui){
$(this).css('opacity', '1');
});
$('.gjg-item').on("drop", function(event, ui){
$('.gjg-item').draggable('destroy');
$('.gjg-item').droppable('destroy');
var idOfItemDropped = ui.draggable[0].id; // css id of item being dropped
idOfItemDropped = idOfItemDropped.replace('gjg-i-', ''); // parse the id
var droppedImgOldPosition = $('#gjg-i-'+idOfItemDropped).attr('data-position'); // get the image being dropped old position
var droppedImgNewPosition = $(this).attr('data-position'); // get the new position where the image was dropped
//console.log('hello');
$.post( DOMAIN+LIBRARY+"grid/ajax/ajax_dragndrop.php", { gridID: gridID, imageID: idOfItemDropped, oldPosition: droppedImgOldPosition, newPosition: droppedImgNewPosition}, function(data) {
if(data.code == 200) {
$('.gjg-item').remove();
ajaxArea('ni');
}
});
});
您可以像这样添加代码来调整dragstop
事件的图像大小:
var original_height = 100;
var original_width = 100;
$('.gjg-item').on('dragstop', function(event, ui) {
$(this).css('z-index', '9999999').width(original_width).height(original_height);
$(this).find('img').width(original_width).height(original_height);
});
相关文章:
- 调整窗口大小时,可拖动的对象会出现在容器外部
- 删除对HTML元素的拖动
- jQuery UI可排序-多连接列表拖动
- 禁用SVG拖动
- 旋转后拖动对象
- JQuery UI可拖动潜水与滚动棒到鼠标
- jsPlumb-拖动克隆而不进行复制
- 当我在节点上拖动鼠标时,我如何防止使用d3.ehavior.zoom().on(“缩放”,重绘)
- 如何使元素在可拖动元素内可单击
- 如何在使用Kinetic拖动同一对象后,在旋转动画中保持先前的偏移
- 在d3中拖动一条线
- 拖放区中可拖动的 Jqueryui 不会滚动,会恢复,滚动条存在
- 如何在拖动时使项目恢复到其原始位置
- 是否有可能知道 jquery 可拖动元素将恢复到哪里
- jQuery UI如果移动的距离小于一定距离,则可拖动恢复到原始位置
- jQuery可拖动改变图像大小在拖动开始,恢复原来的大小在恢复
- jQuery UI可拖动Snap恢复不工作
- JQuery UI可拖动多个恢复选项
- 如何触发交互.js事件/将所有可拖动对象恢复到默认位置(x : 0 , y : 0 )
- 在jQuery中使用像素约束恢复可拖动对象