【发布时间】:2020-12-06 21:54:46
【问题描述】:
我想在 Bootstrap 4 模式弹出窗口中使用 Cloudinary 图像。模态弹出窗口在桌面视图中工作正常,例如模态和图像在视图区域中居中,并且模态按预期工作。
但是,当我使用移动设备(在 Chrome 开发人员中)进行测试时,虽然模态运行良好,但到目前为止,无论我尝试什么,Cloudinary 图像都不会响应大小。
模态HTML如下:
<!-- Creates the bootstrap modal where the image will appear -->
<div class="modal fade" id="imagemodal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-xs">
<div class="modal-content">
<div class="modal-body">
<button type="button" class="close" data-dismiss="modal">
<span aria-hidden="true" class="glyphicon glyphicon-remove"></span>
<span class="sr-only">Close</span>
</button>
<img src="" class="item_photo_pop img-center cld-responsive">
</div>
</div>
</div>
</div>
modal 的javascript如下:
<script>
$(function() {
$('.item_photo').on('click', function() {
var src_url = $.cloudinary.url($(this).attr('id'), { width: 'auto', crop: 'scale', secure: true });
$('.item_photo_pop').attr('src', src_url);
$('#imagemodal').modal('show');
});
});
var cl = cloudinary.Cloudinary.new({cloud_name: "xxxxxxxx"});
cl.responsive();
</script>
使用的css如下:
.modal-dialog {
display: table; /* This makes modal fill view area */
width: 95%;
height: 92%;
padding: 0;
}
.modal-content {
height: 99%;
}
.img-center {
display: block;
margin-left: auto;
margin-right: auto;
}
如果我在没有图像的情况下显示模态,例如设置var src_url = '',那么模态会响应地填充桌面和移动设备的视图区域。
因此很明显,Cloudinary 图像的大小无法响应以适应模式。
如何使 Cloudinary 图像响应大小以适应模式?
编辑添加:
javascript 将img src 网址更新为:https://res.cloudinary.com/xxxxxxxx/image/upload/c_scale,w_auto/rcdvyr8meehm8jg
【问题讨论】:
标签: javascript jquery twitter-bootstrap cloudinary