0
我正在創建一個簡單的滑塊使用jQuery。簡單的圖像滑塊不工作(jQuery)
問題:滑塊正在消失和/或崩潰(在刷新消失之前您可以看到它)。
我在做什麼:使圖像的位置爲absolute
,然後使用JavaScript在腳本中使用display
屬性顯示nth
索引。
不確定它是否是隱藏的CSS或JavaScript。任何想法我做錯了什麼?
$(document).ready(function() {
$('#sidebar-btn').click(function() {
$('#sidebar-nav').toggleClass('visible');
});
});
var index = 0;
function plusIndex(n) {
index = index + 1;
showImage(index);
}
/* SLIDER */
showImage(1);
/* Slider function */
function showImage(n) {
var i;
var x = document.getElementsByClassName("slider-img");
// for next slide - forward.
if(n > x.length) { index = 1 };
// for prev slide - backwards
if(n < 1) { index = x.length /* last one */ };
for(i=0; i<x.length; i++)
{
x[i].style.display = "none";
}
x[index-1].style.display = "block";
}
.updates-box {
background-color: #f5f5f5;
text-align: center;
padding: 2rem;
}
.updates-item-headline {
font-weight: bold;
}
.updates-item {
padding: 1rem;
margin: 1rem auto;
}
.slider {
position: relative;
}
.slider-img {
position: absolute;
}
.slider .slider-btn {
position: absolute; \t
color: black;
width: 50px;
border:none;
border-radius: 25px;
top: 190px;
font-size: 35px;
margin: 1rem;
}
.slider #slide-btn2 {
position: relative;
float: right;
}
.slider #slide-btn1:hover {
box-shadow: 10px 0px 20px 0px black;
}
.slider #slide-btn2:hover {
box-shadow: 10px 0px 20px 0px black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="hero-box">
<div id="slide-wrapper">
<div class="slider">
<div class="slide">
<picture>
<source media="(max-width: 620px)" srcset="img/hero-slider-mobile.jpg">
<source media="(min-width: 621)" srcset="img/hero-slider-tablet.jpg">
<img class="slider-img" src="img/hero-slider-home.jpg" alt="Flowers">
</picture> \t \t \t \t \t \t
</div>
<div class="slide">
<picture>
<source media="(max-width: 620px)" srcset="img/slide-2-mobile.jpg">
<source media="(min-width: 621)" srcset="img/slide-2-tablet.jpg">
<img class="slider-img" src="img/slide-2-home.jpg" alt="Flowers">
</picture> \t \t \t \t \t \t
</div>
<button class="slider-btn" id="slide-btn1">❮</button>
<button class="slider-btn" id="slide-btn2">❯</button>
</div>
</div>
</div>
<div class="updates-box">
<div class="updates-item-headline">
<p> UPCOMING EVENT DATES</p>
</div>
<div class="updates-item">
<img class="update-icon" src="img/dates-icon.png">
<p><b>Thursday 3 August</b></p>
<p> Open Seminar Enrollment</p>
</div>
<div class="updates-item">
<img class="update-icon" src="img/dates-icon.png">
<p><b>Thursday 3 August</b></p>
<p> Open Seminar Enrollment</p>
</div>
<div class="updates-item-4">
<img class="update-icon" src="img/dates-icon.png">
<p><b>Thursday 3 August</b></p>
<p> Open Seminar Enrollment</p>
</div> \t \t
</div>