gpt4 book ai didi

javascript - 重叠的 slider 标题问题

转载 作者:太空宇宙 更新时间:2023-11-04 09:23:56 25 4
gpt4 key购买 nike

我从头开始构建了这个 slider /推子/旋转木马,点的可点击性实现得很好,但是,当您选择特定图像时,由于 slider 的功能仍在使用,因此每个图像的标题都会漏掉实现和运行。有没有办法在用户单击特定点时停止或暂停该功能一段特定时间,然后再次开始运行它?还有另一种方法可以隐藏不活动的字幕吗?我尝试了几种不同的方法,但都无法正常工作。这是代码:

function cycleImages() {
var $active = $('.image.active');
var $next = $active.next().length > 0 ? $active.next() : $('.image:first');
$active.animate({
opacity:'0'
},400,function(){
$active.removeClass('active')
$next.animate({
opacity:'1'
},400,function(){
$next.addClass('active');
})
});
}

$(document).ready(function(){

setInterval('cycleImages()', 7000);

$(".fader, .dots.one").on("click", function(){
if($(this).hasClass("one")) {
$(".dots.one").toggleClass('dot-active');
$(".dots.two, .three, .four, .five").removeClass('dot-active');
$(".image, .img-1").siblings(".img-2, .img-3, .img-4, .img-5").css("opacity", "0");
$(".img-1, .caption").css("opacity", "1");

}
});
$(".fader, .dots.two").on("click", function(){
if($(this).hasClass("two")) {
$(".dots.two").toggleClass('dot-active');
$(".dots.one, .three, .four, .five").removeClass('dot-active');
$(".image, .img-2").siblings(".img-1, .img-3, .img-4, .img-5").css("opacity", "0");
$(".img-2, .caption").css("opacity", "1");

}
});
$(".fader, .dots.three").on("click", function(){
if($(this).hasClass("three")) {
$(".dots.three").toggleClass('dot-active');
$(".dots.one, .two, .four, .five").removeClass('dot-active');
$(".image, .img-3").siblings(".img-1, .img-2, .img-4, .img-5").css("opacity", "0");
$(".img-3, .cp-3").css("opacity", "1");

}
});
$(".fader, .dots.four").on("click", function(){
if($(this).hasClass("four")) {
$(".dots.four").toggleClass('dot-active');
$(".dots.one, .two, .three, .five").removeClass('dot-active');
$(".image, .img-4").siblings(".img-1, .img-2, .img-3, .img-5").css("opacity", "0");
$(".img-4, .cp-4").css("opacity", "1");

}
});
$(".fader, .dots.five").on("click", function(){
if($(this).hasClass("five")) {
$(".dots.five").toggleClass('dot-active');
$(".dots.one, .two, .three, .four").removeClass('dot-active');
$(".image, .img-5").siblings(".img-1, .img-2, .img-3, .img-4").css("opacity", "0");
$(".img-5, .cp-5").css("opacity", "1");

}
});
});
div.image div.caption {
display: visible;
position: absolute;
overflow: hidden;
z-index: 20;
color: white;
background-color: rgba(0,0,0,0.3);
height: 10%;
width: 99.5%;
bottom: 0;
font-family: arial;
font-size: 10pt;
padding: 0.5em;
}
.fader {
height: 40vw;
}

.fader div.image img {
margin-left: -4.25em;
}
.fader {
border-radius: 1em;
height: 25vw;
width: 74vw;
max-height: 100%;
min-height: 10vw;
margin: 0 auto;
border-left: 1.5em solid #aa917d;
border-right: 1.5em solid #aa917d;
position: relative;
overflow: hidden;
}
.fader div.image img {
display: block;
width: 100%;
margin: 0 auto;
z-index: 1;
position: absolute;
}

div.image img {
z-index: 5;
}

div.image{
opacity:0;
transition:all 1s ease-in;
}

div.image.active{
opacity:1;
}

.dots {
float: right;
background-color: rgba(255,255,255,100);
border: none;
border-radius: .85vw;
display: inline-block;
height: .85vw;
width: .85vw;
margin: .2em .2em .2em .2em;
}

.dots.active {
background-color: #aa917d;
}

.dot-container button {
padding: 0px;
}
.dot-container {
float: right;
margin-right: .5em
}
.dot-active {
background-color: #766557;
}

button {
font-family: arial;
color: white;
cursor: pointer;
border: none;
background: none;
padding-left: 0px;

}

button:focus {
outline: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<div class="fader">
<div class="image img-1 active">
<img class="" src="http://media.istockphoto.com/vectors/watercolor-blue-banner-vector-id520176256?s=2048x2048" alt="" style="height: 100%; width:auto; object-fit: fill">
<div class="caption">
<span class="image-info cp-1 active"><a>Harvard Law School - Cambridge, MA</a></span>
<div class="dot-container">
<button><span class="dots five"></span></button>
<button><span class="dots four"></span></button>
<button><span class="dots three"></span></button>
<button><span class="dots two"></span></button>
<button><span class="dots one active"></span></button>
</div>
</div>
</div>
<div class="image img-2">
<img class="" src="http://media.istockphoto.com/illustrations/turquoise-and-chartreuse-mottled-background-with-dotted-pattern-illustration-id505491352?s=2048x2048" alt="" style="height: 100%; width:auto; object-fit: fill">
<div class="caption">
<span class="image-info cp-2"><a>Battery Wharf - Boston, MA</a></span>
<div class="dot-container">
<button><span class="dots five"></span></button>
<button><span class="dots four"></span></button>
<button><span class="dots three"></span></button>
<button><span class="dots two active"></span></button>
<button><span class="dots one"></span></button>
</div>
</div>
</div>
<div class="image img-3">
<img class="" src="http://media.istockphoto.com/illustrations/blank-abstract-light-blue-watercolor-background-illustration-id499570852?s=2048x2048" alt="" style="height: 100%; width:auto; object-fit: fill">
<div class="caption">
<span class="image-info cp-3"><a>Back Bay Hotel - Boston, MA</a></span>
<div class="dot-container">
<button><span class="dots five"></span></button>
<button><span class="dots four"></span></button>
<button><span class="dots three active"></span></button>
<button><span class="dots two"></span></button>
<button><span class="dots one"></span></button>
</div>
</div>
</div>
<div class="image img-4">
<img lass="" src="http://media.istockphoto.com/illustrations/gold-glitter-painted-background-illustration-id512988164?s=2048x2048" alt="" style="height: 100%; width:auto; object-fit: fill">
<div class="caption">
<span class="image-info cp-4"><a>Ashmont MBTA Station - Dorchester, MA</a></span>
<div class="dot-container">
<button><span class="dots five"></span></button>
<button><span class="dots four active"></span></button>
<button><span class="dots three"></span></button>
<button><span class="dots two"></span></button>
<button><span class="dots one"></span></button>
</div>
</div>
</div>
<div class="image img-5">
<img class="" src="http://media.istockphoto.com/illustrations/pink-orange-backgrounds-watercolor-painting-abstract-illustration-id514635080?s=2048x2048" alt="" style="height: 100%; width:auto; object-fit: fill">
<div class="caption">
<span class="image-info cp-5"><a>----------</a></span>
<div class="dot-container">
<button><span class="dots five active"></span></button>
<button><span class="dots four"></span></button>
<button><span class="dots three"></span></button>
<button><span class="dots two"></span></button>
<button><span class="dots one"></span></button>
</div>
</div>
</div>
</div>

最佳答案

我知道的一种方法是您可以使用 setTimeout()

所以在编码中它将是:

$('.dot1').click(function(){
setTimeout( function(){alert("This actually works");}, 2000); // 2000 Means 2 Minutes
});

祝你好运:)

关于javascript - 重叠的 slider 标题问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41291718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com