【发布时间】:2022-01-27 22:10:51
【问题描述】:
我有一张以模态显示的图像。不幸的是,这张图片有一个白色的背景。 只有图像应该显示,白色不应该是可见的。
HTML:
<div id="myModal" class="modal"><div id="close">X</div><img id="modalimg" class="modal-content" src=""></div>
CSS:
.modal-content {
max-height: 850px;
max-width: 1700px;
width: auto;
height: auto;
margin:0 auto;
margin-top: 20px;
object-fit: scale-down;
background-color: #fff;
}
#myModal{
height: 100%;
width:100%;
position:absolute;
background-color: rgba(0, 0, 0, .5);
display: none;
z-index: 20;
}
JS(如果需要):
$('.gallery-img').click(function(){
$('#myModal').css('display', 'block');
var src = $(this).attr('src');
$('.modal-content').attr('src', src);
$('.modal-content').data('src', src);
});
$('#close').click(function(){
$('#myModal').css('display', 'none');
});
编辑 2: 代码笔:Link
【问题讨论】:
-
你的意思是shite背景是图像的一部分吗?您需要裁剪图像,代码无法检测到白色背景并且不显示它(从技术上讲,您可以,但与裁剪图像相比,这是一个巨大的挑战)
-
@StudioTime 否,白色背景不是图像的一部分,白色背景是自动创建的,它取决于图像的宽度和高度,白色背景的大小。如果图像覆盖了白色背景,您将看不到它。
-
你能添加一个工作沙箱吗?
-
@ShivamSharma 从未听说过沙盒。它能做什么?
-
@Rahm6 Sandbox 是您的代码的minimal reproducible example,您也可以使用 StackOverflow 的 "Code Snippet" 意见。
标签: html jquery css bootstrap-modal