gpt4 book ai didi

javascript - jQuery 推子点交互功能

转载 作者:行者123 更新时间:2023-11-28 05:46:02 26 4
gpt4 key购买 nike

如何在推子中实现可点击且功能与我下面的代码类似的指示点。即,当单击相应的点时,它会淡出到与其绑定(bind)的相应图像?我已经创建了这些点,并且可以将它们转换为可点击的按钮,但是如何创建一个函数,该函数是什么?

function cycleImages() {
var $active = $('.image.active'); //get the active tab
var $next = $active.next().length > 0 ? $active.next() : $('.image:first');
//check next length if not present just get the first .image div
//fade out the top image and remove active class from it in callback
$active.animate({
opacity: '0'
}, 400, function() {
$active.removeClass('active')
$next.animate({
opacity: '1'
}, 400, function() {
$next.addClass('active');
})
});
}

// run every 5s
setInterval(cycleImages, 5000);
div.image div.caption {
display: visible;
position: absolute;
overflow: hidden;
z-index: 20;
color: white;
background-color: rgba(0,0,0,0.35);
height: 20%;
width: 100%;
bottom: 0;
}

.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;
}

div.image:not(.active){
display:none;
}

.dots {
float: right;
background-color: rgba(65,45,30,0.5);
border: none;
border-radius: .85vw;
display: inline-block;
height: .85vw;
width: .85vw;
margin: .2em .2em .2em .2em;
}
.dots.active {
background-color: #aa917d;
}

.dot-container {
width: 20%;
float: right;
margin-right: .5em
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="fader">
<div class="image active">
<img class="" src="https://images.contentful.com/256tjdsmm689/2T0QeKcvR6MSsckuKoYIwS/b57d12107fc5eb635e294ed1c76cbbac/feature-gettyimages.jpg" alt="" style="height: 100%; width:auto; object-fit: contain">
<div class="caption">
<span class="image-info">Lorem ipsum dolor sit amet</span>
<div class="dot-container">
<span class="dots"></span>
<span class="dots"></span>
<span class="dots"></span>
<span class="dots"></span>
<span class="dots active"></span>
</div>
</div>
</div>
<div class="image">
<img class="" src="http://www.livemint.com/rf/Image-621x414/LiveMint/Period2/2016/04/09/Photos/DNAnocredit-kuAC--621x414@LiveMint.jpg" alt="" style="height: 100%; width:auto; object-fit: contain">
<div class="caption">
<span class="image-info">Lorem ipsum dolor sit amet</span>
<div class="dot-container">
<span class="dots"></span>
<span class="dots"></span>
<span class="dots"></span>
<span class="dots active"></span>
<span class="dots"></span>
</div>
</div>
</div>
<div class="image">
<img class="" src="http://i.dailymail.co.uk/i/pix/2016/03/22/13/32738CEB00000578-3504412-image-a-4_1458654503277.jpg" alt="" style="height: 100%; width:auto; object-fit: contain">
<div class="caption">
<span class="image-info">Lorem ipsum dolor sit amet</span>
<div class="dot-container">
<span class="dots"></span>
<span class="dots"></span>
<span class="dots active"></span>
<span class="dots"></span>
<span class="dots"></span>
</div>
</div>
</div>
<div class="image">
<img lass="" src="http://static.bigstockphoto.com/images/homepage/2016_bigstock_video.jpg" alt="" style="height: 100%; width:auto; object-fit: contain">
<div class="caption">
<span class="image-info">Lorem ipsum dolor sit amet</span>
<div class="dot-container">
<span class="dots"></span>
<span class="dots active"></span>
<span class="dots"></span>
<span class="dots"></span>
<span class="dots"></span>
</div>
</div>
</div>
<div class="image">
<img class="" src="http://media.tinmoitruong.vn/public/media/media/picture/03/kh4.jpg" alt="" style="height: 100%; width:auto; object-fit: contain">
<div class="caption">
<span class="image-info">Lorem ipsum dolor sit amet</span>
<div class="dot-container">
<span class="dots active"></span>
<span class="dots"></span>
<span class="dots"></span>
<span class="dots"></span>
<span class="dots"></span>
</div>
</div>
</div>
</div>

最佳答案

您需要执行一些操作才能使用点浏览幻灯片:

  • 循环点元素,对每个点应用一个属性(一个数字,从 0 或 1 开始),并为每个点递增 1。
  • 循环遍历图像,对每个图像应用一个属性(一个从 0 或 1 开始的数字),并为每个点加 1。 (就像点一样)
  • 向点添加点击事件处理程序,以获取该特定点的数字属性并显示具有相同数字属性的图像。
  • 删除每张幻灯片上点的标记,所有幻灯片仅使用一组点(这需要调整您的 HTML/CSS)

我建议查看具有此功能的现有轮播,以便更好地理解代码。看看这个blog post from Barrel titled "Building a Responsive jQuery Carousel Plugin from Scratch. “它具有您正在寻找的功能。

关于javascript - jQuery 推子点交互功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38514500/

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