简体   繁体   English

如何隐藏幻灯片上的溢出而不隐藏箭头?

[英]How to hide overflow on slideshow without hiding arrows?

I want to make the overflow hidden to hide the second image in the slideshow (which if I don't, creates extra space in the bottom of my website) however when I do this, it also hides the arrows next and prev...How do I separate them and still keep the arrows in the correct position? 我想隐藏溢出以隐藏幻灯片中的第二个图像(如果不这样做,则在我的网站底部创建额外的空间),但是当我这样做时,它也隐藏了下一个箭头和上一个箭头。我如何分开它们,但仍将箭头保持在正确的位置?

And how do I make them responsive, let's say using percentage for width without it being misplaced? 以及如何使它们具有响应性,比如说使用宽度百分比而不会放错位置呢? sorry long post. 抱歉,很长的帖子。

Please help! 请帮忙! Thank you. 谢谢。

This is the slideshow code: html 这是幻灯片代码:html

<div class="diy-slideshow">
<figure class="show"> <img src="img/image1.jpg" width="100%" /></figure>
<figure><img src="img/image2.jpg" width="100%" /></figure> 
<span class="prev"><img src="prev.png" width="30px"/></span> <span class="next">
<img src="next.png" width="30px"/></span>
</figure>

css 的CSS

.diy-slideshow {
position: relative;
display: block;
overflow: visible;
width: 90%;
margin-left: 5%;
margin-right: 5%;
}

figure{
position: absolute;
opacity: 0;
overflow: hidden;
transition: 1s opacity;
}
figure.show{
opacity: 1;
position: static;
overflow: hidden;
transition: 1s opacity;
}
.next, .prev{
color: #fff;
position: absolute;
top: 50%;
z-index: 1;
opacity: .5;
user-select: none;
}
.next:hover, .prev:hover{
cursor: pointer;
opacity: 1;
}
.next{
right: -4%;
border-top-left-radius: 3px;
border-bottom-left-radius: 3px;
}
.prev{
left: -4%;
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
}

Javascript Java脚本

<script language="JavaScript1.2">
(function(){

var counter = 0,
$items = document.querySelectorAll('.diy-slideshow figure'),
numItems = $items.length;

var showCurrent = function(){
var itemToShow = Math.abs(counter%numItems);

[].forEach.call( $items, function(el){
el.classList.remove('show');
});

$items[itemToShow].classList.add('show');
};

document.querySelector('.next').addEventListener('click', function() {
counter++;
showCurrent();
}, false);

document.querySelector('.prev').addEventListener('click', function() {
counter--;
showCurrent();
}, false);

})();
</script>

Why don't you just add this maybe 你为什么不添加这个也许

figure{
    /* your CSS */
    display:none;
}
figure.show{
    /* your CSS */
    display:block;
}

?

Or a better solution (with your animation) only keep this : 或更好的解决方案(使用动画)只能保留以下内容:

figure{
    position: absolute;
    opacity: 0;
    transition: 1s opacity;
}
figure.show{
    opacity: 1;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM