gpt4 book ai didi

javascript - 使用 div 更改 Active Slick Carousel

转载 作者:行者123 更新时间:2023-11-29 17:39:51 25 4
gpt4 key购买 nike

我们正在使用 slick carousel这样我们就有了<div class='item__wrapper'>一次只显示一张幻灯片。下面是三个items单击 item 的位置,光滑的旋转木马应该更新。

问题

  1. 使用 item__boxes 时作为slick旋转木马,我们所有的样式都乱七八糟,所以我们不能做$('.item__boxes).slick({});
  2. 点击第一个、第二个或第三个时 itemitem__boxes , item__wrapper始终设置为 slide 3

问题

  • 我们如何设置 item__boxes这样就可以点击那个 item它符合我们的目标吗?例如,点击第二个 itemitem__boxes设置 item__wrapper到第二张幻灯片。

目标/预期结果:

  1. 点击第一个 item , 将第一张幻灯片设置为 item__wrapper 中的事件幻灯片
  2. 点击第二个 item , 将第二张幻灯片设置为 item__wrapper 中的事件幻灯片
  3. 点击第三个 item , 将第三张幻灯片设置为 item__wrapper 中的事件幻灯片
  4. 完成所有目标 1-3不做$('.item__boxes).slick({});

代码:

$('.item__wrapper').slick({

infinite: true,
speed: 1500,
dots: false,
prevArrow: false,
nextArrow: false
});

$('.item__boxes').on('click', function() {

var slickIndex = $(this).attr('data-slick-index');
$('.item__wrapper').slick('slickGoTo', slickIndex);
});
.filter {
width: 100%;
height: 100%;
padding: 45px;
margin-right: -45px;
}
.item {
display: none;
position: relative;
}
.item.active {
display: block;
}
.item1 {
background-image: url("https://placeimg.com/1000/480/nature");
}
.item2 {
background-image: url("https://placeimg.com/640/480/arch");
}
.item3 {
background-image: url("https://placeimg.com/640/480/tech");
}
.item__wrapper {
max-width: 60%;
position: relative;
background-size: cover;
background-repeat: no-repeat;
background-color: rgba(238, 238, 238, 0.5);
}
.item__img img {
top: 0px;
position: absolute;
width: 100% !important;
opacity: 0.5;
}
.item__text {
top: 0px;
position: relative;
min-height: 100%;
line-height: 1.4;
padding-right: 70px;
z-index: 5;
display: flex;
flex-direction: column;
align-items: top;
justify-content: center;
}
.item__boxes {
display: flex;
position: relative;
opacity: 0.9;
}
.item__boxes > div {
border: 1px solid;
}
.col-padding {
padding: 16px 16px 5px 16px;
}
.col-m-12 {
width: 100%;
}
@media (min-width: 1024px) {
.col-t-6 {
width: 50%;
}
}
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.css"/>

<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick-theme.css"/>
<script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.js"></script>

<div class="item__wrapper">
<div class="item active" id='item1'>
<div class="item__text">
<div class="filter">
<h3>Some title 1</h3>
<p>Efficiently communicate sticky quality vectors after compelling growth strategies. Compellingly scale future-proof content rather than enterprise users. Uniquely build scalable applications vis-a-vis performance based functionalities. Monotonectally procrastinate.</p>
</div>
</div>
</div>
<div class="item active" id="item2" >
<div class="item__text">
<div class="filter">
<h3>Some title 2</h3>
<p>Efficiently communicate sticky quality vectors after compelling growth strategies. Compellingly scale future-proof content rather than enterprise users. Uniquely build scalable applications vis-a-vis performance based functionalities. Monotonectally procrastinate.</p>
</div>
</div>
</div>
<div class="item active" id="item3" >
<div class="item__text">
<div class="filter">
<h3>Some title 3</h3>
<p>Efficiently communicate sticky quality vectors after compelling growth strategies. Compellingly scale future-proof content rather than enterprise users. Uniquely build scalable applications vis-a-vis performance based functionalities. Monotonectally procrastinate.</p>
</div>
</div>
</div>


</div>
<div class="item__boxes">
<div class="box col-m-12 col-t-6 col-padding" data-slick-index="-1">
<div>Some Title</div>
<div>Enthusiastically incubate diverse initiatives without multifunctional strategic theme areas.</div>
</div>
<div class="box col-m-12 col-t-6 col-padding" data-slick-index="0">
<div>Globally Title</div>
<div>Globally impact integrated infomediaries via seamless mindshare. </div>
</div>
<div class="box col-m-12 col-t-6 col-padding" data-slick-index="1">
<div>Distinctively Title</div>
<div>Distinctively strategize long-term high-impact ideas whereas client-centered leadership skills.</div>
</div>
</div>

最佳答案

试试这个。

$('.item__wrapper').slick({
infinite: true,
speed: 1500,
dots: false,
prevArrow: false,
nextArrow: false
});

$('[data-slide]').click(function(e){
var slideno = $(this).data('slide');
$('.item__wrapper').slick('slickGoTo', slideno);
});
.filter {
width: 100%;
height: 100%;
padding: 45px;
margin-right: -45px;
}
.item {
display: none;
position: relative;
}
.item.active {
display: block;
}
.item1 {
background-image: url("https://placeimg.com/1000/480/nature");
}
.item2 {
background-image: url("https://placeimg.com/640/480/arch");
}
.item3 {
background-image: url("https://placeimg.com/640/480/tech");
}
.item__wrapper {
max-width: 60%;
position: relative;
background-size: cover;
background-repeat: no-repeat;
background-color: rgba(238, 238, 238, 0.5);
}
.item__img img {
top: 0px;
position: absolute;
width: 100% !important;
opacity: 0.5;
}
.item__text {
top: 0px;
position: relative;
min-height: 100%;
line-height: 1.4;
padding-right: 70px;
z-index: 5;
display: flex;
flex-direction: column;
align-items: top;
justify-content: center;
}
.item__boxes {
display: flex;
position: relative;
opacity: 0.9;
}
.item__boxes > div {
border: 1px solid;
}
.col-padding {
padding: 16px 16px 5px 16px;
}
.col-m-12 {
width: 100%;
}
@media (min-width: 1024px) {
.col-t-6 {
width: 50%;
}
}
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.css"/>

<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick-theme.css"/>
<script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.js"></script>

<div class="item__wrapper">
<div class="item active" id='item1'>
<div class="item__text">
<div class="filter">
<h3>Some title 1</h3>
<p>Efficiently communicate sticky quality vectors after compelling growth strategies. Compellingly scale future-proof content rather than enterprise users. Uniquely build scalable applications vis-a-vis performance based functionalities. Monotonectally procrastinate.</p>
</div>
</div>
</div>
<div class="item" id="item2" >
<div class="item__text">
<div class="filter">
<h3>Some title 2</h3>
<p>Efficiently communicate sticky quality vectors after compelling growth strategies. Compellingly scale future-proof content rather than enterprise users. Uniquely build scalable applications vis-a-vis performance based functionalities. Monotonectally procrastinate.</p>
</div>
</div>
</div>
<div class="item" id="item3" >
<div class="item__text">
<div class="filter">
<h3>Some title 3</h3>
<p>Efficiently communicate sticky quality vectors after compelling growth strategies. Compellingly scale future-proof content rather than enterprise users. Uniquely build scalable applications vis-a-vis performance based functionalities. Monotonectally procrastinate.</p>
</div>
</div>
</div>


</div>
<div class="item__boxes">
<div class="box col-m-12 col-t-6 col-padding" data-slide="0">
<div>Some Title</div>
<div>Enthusiastically incubate diverse initiatives without multifunctional strategic theme areas.</div>
</div>
<div class="box col-m-12 col-t-6 col-padding" data-slide="1">
<div>Globally Title</div>
<div>Globally impact integrated infomediaries via seamless mindshare. </div>
</div>
<div class="box col-m-12 col-t-6 col-padding" data-slide="2">
<div>Distinctively Title</div>
<div>Distinctively strategize long-term high-impact ideas whereas client-centered leadership skills.</div>
</div>
</div>

关于javascript - 使用 div 更改 Active Slick Carousel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53772406/

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