對JavaScript和Stackoverflow來說新的合理的,我只是想將可點擊的按鈕添加到圖片庫。將箭頭添加到圖片庫-JS
對於JavaScript中的下一步,我目前有點失落,關於如何在圖像中循環的任何提示都很棒。
乾杯
https://jsfiddle.net/KrnRbts/zkvu16nv/
HTML:
"use strict";
(function() {
var thumbnails = document.querySelectorAll('.gallery__img'),
imageMain = document.querySelector('.image-main');
var leftArrow = document.querySelector('.material-icons left-btn'),
rightArrow = document.querySelector('.material-icons right-btn');
var currentIndex = 0;
for (var i = 0; i < thumbnails.length; i++) {
thumbnails[i].addEventListener('click', function(evt) {
imageMain.src = evt.target.src.replace('150/100', '1000/400');
});
}
function arrows() {
thumbnails.click();
}
function moveLeft(leftArrow){
for (var j = 0; j < currentIndex.length; j--){
currentIndex--;
}
}
function moveRight(rightArrow){
for (var j = 1; j < currentIndex.length; j++){
currentIndex++;
}
}
})();
JS:
<div class="gallery__wrapper">
<div class="image-main__wrapper">
<img class="image-main" src="https://unsplash.it/g/1000/400?image=0">
<div id="arrows">
<i class='material-icons left-btn'>chevron_left</i>
<i class='material-icons right-btn'>chevron_right</i>
</div>
<div class="image-thumbnails__wrapper">
<ul class="thumbnails">
<li><img id="thumb-1" class="gallery__img" src="https://unsplash.it/g/150/100?image=1"></li>
<li><img id="thumb-2" class="gallery__img" src="https://unsplash.it/g/150/100?image=2"></li>
<li><img id="thumb-3" class="gallery__img" src="https://unsplash.it/g/150/100?image=3"></li>
<li><img id="thumb-4" class="gallery__img" src="https://unsplash.it/g/150/100?image=4"></li>
<li><img id="thumb-5" class="gallery__img" src="https://unsplash.it/g/150/100?image=5"></li>
<li><img id="thumb-6" class="gallery__img" src="https://unsplash.it/g/150/100?image=6"></li>
<li><img id="thumb-7" class="gallery__img" src="https://unsplash.it/g/150/100?image=7"></li>
<li><img id="thumb-8" class="gallery__img" src="https://unsplash.it/g/150/100?image=8"></li>
</ul>
</div>
</div>
</div>
歡迎來到StackOverflow。如果您複製粘貼代碼標記中的相關代碼會更好。這樣我們可以嘗試並理解你所做的事情。你也可以嘗試一個JSFiddle。你可以閱讀[如何問](http://stackoverflow.com/help/how-to-ask)如果你想做更好的問題;) – goto
請在這裏發佈所有代碼 – Li357