如果能夠逐一顯示圖片點擊後,您可以使用相同的代碼/功能並在mousewheel
事件中觸發它。
您可以使用鼠標滾輪插件捕捉mousewheel事件,就像我在下面的示例中所做的一樣。
mousewheel
事件會給你一個變量,那將表明鼠標滾輪是否向上或向下滾動,你可以相應地移動到適當的幻燈片:
$(document).ready(function(){
$("#next").on("click", function(e){
e.preventDefault();
showNextSlide();
});//
$("#prev").on("click", function(e){
e.preventDefault();
showPrevSlide();
});//
$("#slider").on("mousewheel", function(e){
e.preventDefault();
if(e.deltaY < 0){
showNextSlide();
}else{
showPrevSlide();
}
});//#slider mousewheel()
});//document ready()
function showNextSlide(){
var curActiveIndex = $("#slider img.active").index();
var numSlides = $("#slider img").length;
var nextIndex = curActiveIndex >= numSlides - 1 ? 0 : (curActiveIndex + 1);
$("#slider img.active").removeClass("active");
$("#slider img").eq(nextIndex).addClass("active");
}//showNextSlide()
function showPrevSlide(){
var curActiveIndex = $("#slider img.active").index();
var numSlides = $("#slider img").length;
var nextIndex = curActiveIndex <= 0 ? numSlides - 1 : (curActiveIndex - 1);
$("#slider img.active").removeClass("active");
$("#slider img").eq(nextIndex).addClass("active");
}//showPrevSlide()
#slider{
height: 200px;
position: relative;
width: 400px;
}
#slider img{
left: 0;
opacity: 0;
position: absolute;
top: 0;
transition: opacity 0.8s linear;
}
#slider img.active{
opacity: 1;
}
.as-console-wrapper{display: none !important;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.13/jquery.mousewheel.js"></script>
<div id="slider">
<img class="active" src="http://lorempixel.com/400/200/sports" alt="Slide 1" />
<img src="http://lorempixel.com/400/200/food" alt="Slide 1" />
<img src="http://lorempixel.com/400/200/nature" alt="Slide 1" />
<img src="http://lorempixel.com/400/200/fashion" alt="Slide 1" />
<img src="http://lorempixel.com/400/200/cats" alt="Slide 1" />
</div><!--#slider-->
<div>
<button id="prev">previous</button>
<button id="next">next</button>
</div>
這麼,你應該張貼您的用迄今爲止所做的代碼提出問題。然後人們可以幫助你。這不是讓某人爲你編碼的地方。如果你願意,請檢查一些自由職業者的網站,以獲得相同的程序員。 –
請告訴我們您已經嘗試過 –
k我將顯示我的代碼 –