#html #css #slideshow #adobe-brackets
#HTML #css #слайд-шоу #adobe-скобки
Вопрос:
Я пытаюсь создать карусель изображений для веб-сайта, я закодировал это в скобках, что показывает в предварительном просмотре в скобках, что это выглядит так: []
тем не менее, когда я открываю его в Chrome, нажав на мой index.js это заставляет первое изображение принять решение не появляться, пока не появится второе изображение.
и когда я загружаю код на сайт github и полностью обновляю его. это выглядит следующим образом []
его даже нет в том контейнере, который я для него закодировал.
и когда я нажимаю на стрелку, она переводит меня на следующую фотографию, которая отображается как это []
это как если бы он даже не создавал контейнер и не вставлял в него изображение..
мой код выглядит следующим образом:
var slideIndex = 1;
showSlides(slideIndex);
// Next/previous controls
function plusSlides(n) {
showSlides(slideIndex = n);
}
// Thumbnail image controls
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dot");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i ) {
slides[i].style.display = "none";
}
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";
}
outer {
display: flex;
align-items: center;
justify-content: center;
animation: slideInRight ease 1s;
}
@keyframes slideInRight {
0% {
opacity: 1;
transform: translate3d(100%, 0, 0);
}
100% {
opacity: 1;
transform: none;
}
}
.wrapper {
display: grid;
grid-template-columns: 1fr;
grid-gap: 100px;
margin-top: 75px;
align-content: center;
text-align: center
}
.element {
display: grid;
grid-template-areas: "dsc lgo" "ttl lgo";
grid-template-rows: auto 1fr;
grid-template-columns: auto 1fr;
grid-gap: 10px;
animation: fadeInAnimation ease 2s;
}
@keyframes fadeInAnimation {
0% {
opacity: 0;
}
50% {
opacity: 0;
}
100% {
opacity: 1;
}
}
/* Slideshow container */
.slideshow-container {
max-width: 1000px;
position: relative;
margin: auto;
}
/* Hide the images by default */
.mySlides {
display: none;
}
/* Next amp; previous buttons */
.prev, .next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
margin-top: -22px;
padding: 16px;
color: white;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
}
/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
/* Position the "next button" to the right */
.prev {
left: 0;
border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover, .next:hover {
background-color: rgba(0,0,0,0.8);
}
/* Caption text */
.text {
color: #f2f2f2;
font-size: 15px;
padding: 8px 0px;
position: absolute;
bottom: 8px;
width: 100%;
text-align: center;
background-color: rgba(26, 26, 26, 0.6);
margin-bottom: 20px;
}
/* The dots/bullets/indicators */
.dot {
cursor: pointer;
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
.active, .dot:hover {
background-color: #717171;
}
/* Sliding animation */
.fade {
-webkit-animation-name: fade;
-webkit-animation-duration: 1.5s;
animation-name: fade;
animation-duration: 1.5s;
}
@-webkit-keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
@keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
<div class='outer'>
<div class='wrapper'>
<div class='element'>
<!-- Slideshow container -->
<!-- Slideshow container -->
<div class="slideshow-container">
<!-- Full-width images with number and caption text -->
<div class="mySlides fade">
<img src="/images/wallpaper2you_482698.jpg" style="width:100%">
<div class="text">Caption Text</div>
</div>
<div class="mySlides fade">
<img src="images/wwwallpaper2you_482698.jpg" style="width:100%">
<div class="text">Caption Two</div>
</div>
<div class="mySlides fade">
<img src="images/wwallpaper2you_482698.jpg" style="width:100%">
<div class="text">Caption Three</div>
</div>
<!-- Next and previous buttons -->
<a class="prev" onclick="plusSlides(-1)">amp;#10094;</a>
<a class="next" onclick="plusSlides(1)">amp;#10095;</a>
</div>
<br>
<!-- The dots/circles -->
<div style="text-align:center">
<span class="dot" onclick="currentSlide(1)"></span>
<span class="dot" onclick="currentSlide(2)"></span>
<span class="dot" onclick="currentSlide(3)"></span>
</div>
</div>
</div>
</div>
может кто-нибудь, пожалуйста, помогите мне !?
Ответ №1:
Ваш исходный код в порядке, просто перепроверьте файл пути к изображению. В противном случае полностью удалите данные на github, а затем повторно загрузите их.
var slideIndex = 1;
showSlides(slideIndex);
// Next/previous controls
function plusSlides(n) {
showSlides(slideIndex = n);
}
// Thumbnail image controls
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dot");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i ) {
slides[i].style.display = "none";
}
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";
}
outer {
display: flex;
align-items: center;
justify-content: center;
animation: slideInRight ease 1s;
}
@keyframes slideInRight {
0% {
opacity: 1;
transform: translate3d(100%, 0, 0);
}
100% {
opacity: 1;
transform: none;
}
}
.wrapper {
display: grid;
grid-template-columns: 1fr;
grid-gap: 100px;
margin-top: 75px;
align-content: center;
text-align: center
}
.element {
display: grid;
grid-template-areas: "dsc lgo" "ttl lgo";
grid-template-rows: auto 1fr;
grid-template-columns: auto 1fr;
grid-gap: 10px;
animation: fadeInAnimation ease 2s;
}
@keyframes fadeInAnimation {
0% {
opacity: 0;
}
50% {
opacity: 0;
}
100% {
opacity: 1;
}
}
/* Slideshow container */
.slideshow-container {
max-width: 1000px;
position: relative;
margin: auto;
}
/* Hide the images by default */
.mySlides {
display: none;
}
/* Next amp; previous buttons */
.prev, .next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
margin-top: -22px;
padding: 16px;
color: white;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
}
/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
/* Position the "next button" to the right */
.prev {
left: 0;
border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover, .next:hover {
background-color: rgba(0,0,0,0.8);
}
/* Caption text */
.text {
color: #f2f2f2;
font-size: 15px;
padding: 8px 0px;
position: absolute;
bottom: 8px;
width: 100%;
text-align: center;
background-color: rgba(26, 26, 26, 0.6);
margin-bottom: 20px;
}
/* The dots/bullets/indicators */
.dot {
cursor: pointer;
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
.active, .dot:hover {
background-color: #717171;
}
/* Sliding animation */
.fade {
-webkit-animation-name: fade;
-webkit-animation-duration: 1.5s;
animation-name: fade;
animation-duration: 1.5s;
}
@-webkit-keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
@keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
<div class='outer'>
<div class='wrapper'>
<div class='element'>
<!-- Slideshow container -->
<!-- Slideshow container -->
<div class="slideshow-container">
<!-- Full-width images with number and caption text -->
<div class="mySlides fade">
<img src="a.jpg" style="width:100%">
<div class="text">Caption Text</div>
</div>
<div class="mySlides fade">
<img src="d.jpg" style="width:100%">
<div class="text">Caption Two</div>
</div>
<div class="mySlides fade">
<img src="w.jpg" style="width:100%">
<div class="text">Caption Three</div>
</div>
<!-- Next and previous buttons -->
<a class="prev" onclick="plusSlides(-1)">amp;#10094;</a>
<a class="next" onclick="plusSlides(1)">amp;#10095;</a>
</div>
<br>
<!-- The dots/circles -->
<div style="text-align:center">
<span class="dot" onclick="currentSlide(1)"></span>
<span class="dot" onclick="currentSlide(2)"></span>
<span class="dot" onclick="currentSlide(3)"></span>
</div>
</div>
</div>
</div>
Комментарии:
1. Спасибо, чувак! И я знаю, что мой исходный файл изображения испорчен. Я забыл изменить его на ссылку для демонстрации переполнения стека. Я попробую полностью очистить github и просто надеюсь, что это сработает
2. Спасибо, приятель, пожалуйста, поддержите, если сочтете полезным.
3. Я отмечаю ваш комментарий как принятый, поскольку он был причиной того, что github даже ничего не отображал. но у меня был абсолютный путь к первому изображению, из-за чего оно не отображалось. спасибо за помощь!