提问人:Bokijonov 提问时间:8/15/2022 更新时间:8/17/2022 访问量:327
灯箱图库导航图像:如何将选定的活动图像居中
Lightbox gallery navigation images: How to center selected active image
问:
你好,我正在我的 Django 应用程序上使用。当用户单击其中一个图像时,图库将出现带有 、功能图标和导航部分的所有图像。我正在尝试通过浮动到屏幕左侧来激活选定的图像。Lightbox gallery
main selected image
next
prev
center
法典:
JS公司
<script type="text/javascript">
function openModal() {
document.getElementById("myModal").style.display = "block";
}
function closeModal() {
document.getElementById("myModal").style.display = "none";
}
var slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("demo");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
}
</script>
{% endblock %}
[HTML全
<div id="myModal" class="modal">
<div class="close-modal-container">
<a href="#" class="btn d-flex align-items-center text-light" onclick="closeModal()" aria-label="{% trans "Close" %}">
<span class="close-icon">{% icon 'CLOSE' 20 version='v2' %}</span>
<span class="gr-link2 ml-2">{% trans "Close" %}</span>
</a>
</div>
<div class="body-container">
{% for file in files %}
{% if file.is_image %}
<div class="mySlides">
<div class="image-icon-cont">
<div class="d-flex flex-column">
<img class="modal-main-img" src="{{ file.file.url }}" alt="{{ file.tag }}">
<div class="my-1 text-light">
<span class="mr-1 subtitle1">{{ forloop.counter }} / {{ files|length }}</span>
<span class="subtitle1">{{ file.tag }}</span>
</div>
</div>
<a class="prev" onclick="plusSlides(-1)">{% icon "ARROW_LEFT" 24 version='v2' %}</a>
<a class="next" onclick="plusSlides(1)">{% icon "ARROW_RIGHT" 24 version='v2' %}</a>
</div>
</div>
{% endif %}
{% endfor %}
<div class="image-file-bottom-slides">
{% for file in files %}
{% if file.is_image %}
<img class="demo cursor slide-image mx-2" src="{{ file.file.url }}" alt="{{ file.tag }}" onclick="currentSlide({{ forloop.counter }})">
{% endif %}
{% endfor %}
</div>
</div>
</div>
CSS的
/* The Modal (background) */
.modal {
display: none;
position: fixed;
left: 50%;
top: 50%;
width: 100vw;
height: 100vh;
overflow: auto;
background-color: #212121;
transform: translate(-50%, -50%);
max-height: none;
max-width: 100%;
::-webkit-scrollbar{
display: none !important;
}
}
/* Next & previous buttons */
.prev {
position: absolute;
cursor: pointer;
padding: 10px;
background-color: #FFFFFF;
color: #212121;
border-radius: 3px;
left: 15px;
top: 50%;
transform: translate(-50%, -50%);
}
.next {
position: absolute;
cursor: pointer;
padding: 10px;
background-color: #FFFFFF;
color: #212121;
border-radius: 3px;
right: -30px;
top: 50%;
transform: translate(-50%, -50%);
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover,
.next:hover {
background-color: #F2F2F2;
}
.modal-main-img {
width: 70vw;
height: 70vh;
object-fit: cover;
}
.active,
.demo:hover {
opacity: 0.6 !important;
}
.modal-main-img.hover-shadow {
transition: 0.3s;
}
.hover-shadow:hover {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
.slide-image{
width: 137.67px;
height: 94px;
cursor: pointer;
opacity: 1;
border-radius: 3px;
}
.image-file-bottom-slides{
display: flex;
background-color: #212121;
flex-wrap: nowrap;
overflow-y: hidden;
overflow-x: scroll;
justify-content: flex-end;
}
.image-file-bottom-slides::-webkit-scrollbar {
display: none;
}
.mySlides{
background-color: #212121;
}
.image-icon-cont{
position: relative;
display: flex;
justify-content: center;
}
.body-container{
padding: 40px;
}
我怎样才能将选定的图像和图像导航部分居中。active
float images to the left
答:
0赞
user123
8/17/2022
#1
我试图完全理解您的问题,您的意思是您希望能够在选择时将所选图像从任何索引移动到索引 0?
如果是这样,您可以将元素附加到其父元素之前$(this).parent().prepend(this)
评论
0赞
Bokijonov
8/17/2022
是的,这就是我的本意。不是我想要的100%,但这可能会有所帮助。我可以获取此图像的整个项目代码吗?谢谢
0赞
user123
8/17/2022
哦,很酷 github.com/DannStormy/bg-carousel.git 如果您必须在自己这边测试它,您应该调整图像路径
评论