调整一个图像后,用鼠标调整一行中其余图像的大小,并保持比例
Resizing by mouse the rest of images in a row after resizing a one, and keep ratio
我正在使用jQuery ui Resizable
调整大小后,所有图像都应同时更新:它们的高度和宽度。但是对于用户实际上没有调整大小的图像,只会更新高度。所以图像变得扭曲。如何改进我的代码以在调整大小时保持所有图像的比例?
* {
margin: 0;
padding: 0;
}
.outer {
border: red dashed 2px;
position: relative;
}
.ui-wrapper, .member {
display: inline-block;
object-fit: cover;
}
.member, .ui-wrapper {
width:auto;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<div class="outer">
<img class="res image member" src="https://via.placeholder.com/150x50" alt="" />
<img class="res image member" src="https://via.placeholder.com/100x50" alt="" />
<img class="res image member" src="https://via.placeholder.com/100x50" alt="" />
</div>
<script>
$(".res").resizable({
aspectRatio: true,
ghost: true,
stop: function( event, ui) {
height=ui.size.height;
$(".ui-wrapper, .member").height(height + "px");
}});
</script>
编辑
代码片段不起作用,所以我添加了调整大小前后的屏幕截图:
中间图片调整大小后:
编辑2
还有一个演示:
* {
margin: 0;
padding: 0;
}
.outer {
border: red dashed 2px;
}
.ui-wrapper, .member {
display: inline-block;
vertical-align: top;
}
js:
$(".res").resizable({
aspectRatio: true,
// ghost: true,
stop: function(event, ui) {
height=ui.size.height;
// $(".ui-wrapper, .member").height(height + "px");
$(".ui-wrapper, .member").each(function() {
ratio = height / $(this).height();
console.log(parseInt($(this).height() * ratio, 10));
$(this).css("height", parseInt($(this).height() * ratio, 10));
$(this).css("width", parseInt($(this).width() * ratio, 10));
});
}
});
我正在使用jQuery ui Resizable
调整大小后,所有图像都应同时更新:它们的高度和宽度。但是对于用户实际上没有调整大小的图像,只会更新高度。所以图像变得扭曲。如何改进我的代码以在调整大小时保持所有图像的比例?
* {
margin: 0;
padding: 0;
}
.outer {
border: red dashed 2px;
position: relative;
}
.ui-wrapper, .member {
display: inline-block;
object-fit: cover;
}
.member, .ui-wrapper {
width:auto;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<div class="outer">
<img class="res image member" src="https://via.placeholder.com/150x50" alt="" />
<img class="res image member" src="https://via.placeholder.com/100x50" alt="" />
<img class="res image member" src="https://via.placeholder.com/100x50" alt="" />
</div>
<script>
$(".res").resizable({
aspectRatio: true,
ghost: true,
stop: function( event, ui) {
height=ui.size.height;
$(".ui-wrapper, .member").height(height + "px");
}});
</script>
编辑
代码片段不起作用,所以我添加了调整大小前后的屏幕截图:
中间图片调整大小后:
编辑2
还有一个演示:
* {
margin: 0;
padding: 0;
}
.outer {
border: red dashed 2px;
}
.ui-wrapper, .member {
display: inline-block;
vertical-align: top;
}
js:
$(".res").resizable({
aspectRatio: true,
// ghost: true,
stop: function(event, ui) {
height=ui.size.height;
// $(".ui-wrapper, .member").height(height + "px");
$(".ui-wrapper, .member").each(function() {
ratio = height / $(this).height();
console.log(parseInt($(this).height() * ratio, 10));
$(this).css("height", parseInt($(this).height() * ratio, 10));
$(this).css("width", parseInt($(this).width() * ratio, 10));
});
}
});