我有一个带有文本的滑块选项卡和相关的背景图像。当我单击滑块选项卡时,相关的图像应以滑动动画显示。滑块图像中出现问题。如果再次单击该图像时,If条件不起作用,则该图像不显示。 `
HTML:
<div class="ce-slider-wrapper">
<div class="ce-slider-images-wrapper" id="csw">
<div class="ce-slider-image active-frame" id="ce-img1C">
<img src="https://cdn2.hubspot.net/hubfs/5215930/core-experience/svasahome.png" alt="Core Experience">
</div>
<div class="ce-slider-image" id="ce-img2C">
<img src="https://cdn2.hubspot.net/hubfs/5215930/core-experience/Livingroom%20Classic%201.png" alt="Core Experience">
</div>
<div class="ce-slider-image" id="ce-img3C">
<img src="https://cdn2.hubspot.net/hubfs/5215930/core-experience/indivillage.png" alt="Core Experience">
</div>
</div>
<div class="ce-slider-thumbs" id="ce-thumbs">
<div class="ce-slider-content">
<div class="ce-desc" id="ce-img1">
<div class="ce-desc-subheading">
<div class="ce-desc-line"></div>
<p>01 / SVASA HOMES</p>
</div>
<div class="ce-desc-text">
<p>The Revival of Ancient Wisdom</p>
</div>
</div>
</div>
<div class="ce-slider-content">
<div class="ce-desc" id="ce-img2">
<div class="ce-desc-subheading">
<div class="ce-desc-line"></div>
<p>02 / VAYATHI WEAVES</p>
</div>
<div class="ce-desc-text">
<p>Weaving A Grand New Story</p>
</div>
</div>
</div>
<div class="ce-slider-content">
<div class="ce-desc" id="ce-img3">
<div class="ce-desc-subheading">
<div class="ce-desc-line"></div>
<p>03 / THOTA</p>
</div>
<div class="ce-desc-text">
<p>Uplifting Farmers From The Ground Up</p>
</div>
</div>
</div>
</div>
</div>
jQuery:
$(document).ready(function() {
$('.ce-slider-thumbs').slick({
slidesToShow: 2,
slidesToScroll: 1,
autoplay: true,
infinite: true,
arrows: false,
dots: false,
fade: false,
centerMode: false,
autoplaySpeed: 2000,
focusOnSelect: true,
draggable: false
});
$('#ce-thumbs .ce-desc:not(:first)').addClass('inactive');
$('.ce-slider-image').hide();
$('.active-frame').show();
$('.ce-desc').click(function() {
var css = $(this).attr('id');
if ($(this).hasClass('inactive')) { //this is the start of our condition
$('.ce-desc').addClass('inactive');
$(this).removeClass('inactive');
$(this).addClass('active-tab');
$('.ce-slider-image').hide();
$('#' + css + 'C').css('display', 'block');
}
});
});
CSS:
.ce-slider-wrapper {
width: 100%;
height: 100vh;
position: relative;
}
.ce-slider-image {
width: 100%;
height: 100vh;
}
.ce-slider-image img {
width: 100%;
height: 100%;
object-fit: cover;
}
.ce-slider-thumbs {
position: absolute;
bottom: 20px;
left: 0px;
right: 0px;
display: flex;
width: 60%;
margin: auto;
outline: none;
justify-content: space-between;
}
.ce-slider-content {
width: 30%;
color: #fff;
}
.ce-desc {
display: flex;
flex-direction: column;
}
.ce-desc-line {
width: 180px;
height: 5px;
background: #b7b7b7;
opacity: 0.5;
}
.ce-desc-subheading p {
font-size: 14px;
color: #fff;
font-family: arial;
letter-spacing: 0.35rem;
}
.slick-cloned {
display: none;
}
我有一个带有文本的滑块选项卡和相关的背景图像。每当我单击滑块选项卡时,相关的图像都应该可以通过滑动动画看到。 滑块图像中出现问题,如果我再次单击该图像时,如果“条件”不起作用,则显示“否”。
答案 0 :(得分:2)
我添加了光滑的滑块属性'asNavFor',用于链接主滑块和Thumb滑块。
$(document).ready(function() {
$('.ce-slider-thumbs').slick({
slidesToShow: 2,
slidesToScroll: 1,
autoplay: false,
infinite: true,
arrows: false,
dots: false,
fade: false,
centerMode: false,
autoplaySpeed: 2000,
focusOnSelect: true,
draggable: false,
asNavFor: '.ce-slider-images-wrapper'
});
$('.ce-slider-images-wrapper').slick({
slidesToShow: 1,
slidesToScroll: 1,
autoplay: false,
infinite: true,
arrows: false,
dots: false,
fade: true,
useCSS: false,
centerMode: false,
autoplaySpeed: 2000,
focusOnSelect: true,
draggable: false,
asNavFor: '.ce-slider-thumbs'
});
});
.ce-slider-wrapper {
width: 100%;
height: 100vh;
position: relative;
}
.ce-slider-image {
width: 100%;
height: 100vh;
}
.ce-slider-image img {
width: 100%;
height: 100%;
object-fit: cover;
}
.ce-slider-thumbs.slick-slider {
position: absolute;
}
.ce-slider-thumbs {
position: absolute;
bottom: 20px;
left: 0px;
right: 0px;
display: flex;
width: 60%;
margin: auto;
outline: none;
justify-content: space-between;
}
.ce-slider-content {
width: 30%;
color: #fff;
}
.ce-desc {
display: flex;
flex-direction: column;
}
.ce-desc-line {
width: 180px;
height: 5px;
background: #b7b7b7;
opacity: 0.5;
}
.ce-desc-subheading p {
font-size: 14px;
color: #fff;
font-family: arial;
letter-spacing: 0.35rem;
}
.slick-cloned {
display: none;
}
/*== Add this extra CSS ==*/
.ce-slider-images-wrapper .slick-slide{
opacity: 0 !important;
}
.ce-slider-images-wrapper .slick-slide.slick-active{
opacity: 1 !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.js"></script>
<div class="ce-slider-wrapper">
<div class="ce-slider-images-wrapper" id="csw">
<div class="ce-slider-image active-frame" id="ce-img1C">
<img src="https://cdn2.hubspot.net/hubfs/5215930/core-experience/svasahome.png" alt="Core Experience">
</div>
<div class="ce-slider-image" id="ce-img2C">
<img src="https://cdn2.hubspot.net/hubfs/5215930/core-experience/Livingroom%20Classic%201.png" alt="Core Experience">
</div>
<div class="ce-slider-image" id="ce-img3C">
<img src="https://cdn2.hubspot.net/hubfs/5215930/core-experience/indivillage.png" alt="Core Experience">
</div>
</div>
<div class="ce-slider-thumbs" id="ce-thumbs">
<div class="ce-slider-content">
<div class="ce-desc" id="ce-img1">
<div class="ce-desc-subheading">
<div class="ce-desc-line"></div>
<p>01 / SVASA HOMES</p>
</div>
<div class="ce-desc-text">
<p>The Revival of Ancient Wisdom</p>
</div>
</div>
</div>
<div class="ce-slider-content">
<div class="ce-desc" id="ce-img2">
<div class="ce-desc-subheading">
<div class="ce-desc-line"></div>
<p>02 / VAYATHI WEAVES</p>
</div>
<div class="ce-desc-text">
<p>Weaving A Grand New Story</p>
</div>
</div>
</div>
<div class="ce-slider-content">
<div class="ce-desc" id="ce-img3">
<div class="ce-desc-subheading">
<div class="ce-desc-line"></div>
<p>03 / THOTA</p>
</div>
<div class="ce-desc-text">
<p>Uplifting Farmers From The Ground Up</p>
</div>
</div>
</div>
</div>
</div>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.css" />
答案 1 :(得分:0)
检查是否适合您 作为参考,您也可以检查https://www.w3schools.com/howto/howto_js_slideshow.asp此链接。希望对你有帮助 我将文本包含在一张幻灯片中,仅供参考。也可以将其用于其他幻灯片
var slideIndex = 0;
showSlides();
function showSlides() {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dot");
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slideIndex++;
if (slideIndex > slides.length) {slideIndex = 1}
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";
setTimeout(showSlides, 2000); // Change image every 2 seconds
}
* {box-sizing: border-box;}
body {
font-family: Verdana, sans-serif;
}
.mySlides {
display: none;
}
img {
vertical-align: middle;
}
/* Slideshow container */
.slideshow-container {
max-width: 1000px;
position: relative;
margin: auto;
}
/* Caption text */
.text {
color: #f2f2f2;
font-size: 15px;
padding: 8px 12px;
position: absolute;
bottom: 8px;
width: 100%;
text-align: center;
}
/* Number text (1/3 etc) */
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}
/* The dots/bullets/indicators */
.dot {
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
.active {
background-color: #717171;
}
/* Fading animation */
.fade {
-webkit-animation-name: fade;
-webkit-animation-duration: 1.5s;
animation-name: fade;
animation-duration: 1.5s;
}
.ce-slider-content {
width: 30%;
color: #fff;
display: inline-flex;
}
.ce-desc {
display: flex;
flex-direction: column;
}
.ce-desc-line {
width: 180px;
height: 5px;
background: #b7b7b7;
opacity: 0.5;
}
.ce-desc-subheading p {
font-size: 14px;
color: #fff;
font-family: arial;
letter-spacing: 0.35rem;
}
.slick-cloned {
display: none;
}
@-webkit-keyframes fade {
from {
opacity: .4
}
to {
opacity: 1
}
}
@keyframes fade {
from {
opacity: .4
}
to {
opacity: 1
}
}
/* On smaller screens, decrease text size */
@media only screen and (max-width: 300px) {
.text {
font-size: 11px
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div class="slideshow-container">
<div class="mySlides fade">
<img src="https://i.imgur.com/v9f1nS2.jpg" style="width:100%">
<div class="text">
<div class="ce-slider-content">
<div class="ce-desc" id="ce-img1">
<div class="ce-desc-subheading">
<div class="ce-desc-line"></div>
<p>01 / SVASA HOMES</p>
</div>
<div class="ce-desc-text">
<p>The Revival of Ancient Wisdom</p>
</div>
</div>
</div>
<div class="ce-slider-content">
<div class="ce-desc" id="ce-img2">
<div class="ce-desc-subheading">
<div class="ce-desc-line"></div>
<p>02 / VAYATHI WEAVES</p>
</div>
<div class="ce-desc-text">
<p>Weaving A Grand New Story</p>
</div>
</div>
</div>
<div class="ce-slider-content">
<div class="ce-desc" id="ce-img3">
<div class="ce-desc-subheading">
<div class="ce-desc-line"></div>
<p>03 / THOTA</p>
</div>
<div class="ce-desc-text">
<p>Uplifting Farmers From The Ground Up</p>
</div>
</div>
</div>
</div>
</div>
<div class="mySlides fade">
<img src="https://i.imgur.com/v9f1nS2.jpg" style="width:100%">
<div class="text">Caption Two</div>
</div>
<div class="mySlides fade">
<img src="https://i.imgur.com/v9f1nS2.jpg" style="width:100%">
<div class="text">Caption Three</div>
</div>
</div>
<br>
<div style="text-align:center">
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
</div>
</body>
</html>