【发布时间】:2019-06-26 09:38:42
【问题描述】:
我正在通过 jQuery 附加一个 img 元素,并尝试在单击事件时将 box-shadow 添加到图像的所有侧面。然而,阴影只出现在图像的左侧。如何在图像的所有侧面添加阴影?
var someNumbers = [1, 2, 3];
$.each(someNumbers, function(index, element) {
$('#collection').append('<img src="' + someNumbers[index] + '"/>');
});
$('#collection img').on({
click: function() {
$('#mainImage').attr('src', $(this).attr('src'));
$(this).addClass('selectedImgStyle');
}
});
#collection {
position: absolute;
height: 100px;
width: 500px;
left: 50%;
transform: translate(-50%);
margin-top: 2%;
display: inline-block;
white-space: nowrap;
border-radius: 20px;
overflow: visible;
overflow-x: scroll;
}
#collection img {
height: 100px;
width: 100px;
cursor: pointer;
}
.selectedImgStyle {
box-shadow: 0px 0px 50px red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="collection"></div>
【问题讨论】:
-
这是由
#collection上的溢出引起的。除了在img中添加一些margin来为box-shadow留出空间,您无能为力
标签: jquery html image css box-shadow