Слайд шоу картинок html

How TO — Slideshow

Learn how to create a responsive slideshow with CSS and JavaScript.

A slideshow is used to cycle through elements:

Create A Slideshow

Step 1) Add HTML:

Example

Step 2) Add CSS:

Style the next and previous buttons, the caption text and the dots:

Example

/* Slideshow container */
.slideshow-container max-width: 1000px;
position: relative;
margin: auto;
>

/* Hide the images by default */
.mySlides display: none;
>

/* Next & 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;
>

/* 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 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 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;
>

/* Fading animation */
.fade animation-name: fade;
animation-duration: 1.5s;
>

Step 3) Add JavaScript:

Example

let slideIndex = 1;
showSlides(slideIndex);

Читайте также:  Создать свой лог на java

// Next/previous controls
function plusSlides(n) showSlides(slideIndex += n);
>

// Thumbnail image controls
function currentSlide(n) showSlides(slideIndex = n);
>

function showSlides(n) let i;
let slides = document.getElementsByClassName(«mySlides»);
let dots = document.getElementsByClassName(«dot»);
if (n > slides.length)
if (n < 1)
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»;
>

Automatic Slideshow

To display an automatic slideshow, use the following code:

Example

let slideIndex = 0;
showSlides();

function showSlides() let i;
let slides = document.getElementsByClassName(«mySlides»);
for (i = 0; i < slides.length; i++) slides[i].style.display = "none";
>
slideIndex++;
if (slideIndex > slides.length)
slides[slideIndex-1].style.display = «block»;
setTimeout(showSlides, 2000); // Change image every 2 seconds
>

Multiple Slideshows

Example

let slideIndex = [1,1];
/* Class the members of each slideshow group with different CSS classes */
let slideId = [«mySlides1», «mySlides2»]
showSlides(1, 0);
showSlides(1, 1);

function plusSlides(n, no) showSlides(slideIndex[no] += n, no);
>

function showSlides(n, no) let i;
let x = document.getElementsByClassName(slideId[no]);
if (n > x.length)
if (n < 1)
for (i = 0; i < x.length; i++) x[i].style.display = "none";
>
x[slideIndex[no]-1].style.display = «block»;
>

Источник

Learn how to create a responsive slideshow gallery with CSS and JavaScript.

A slideshow is used to cycle through elements:

The Woods

Cinque Terre

Mountains and fjords

Northern Lights

Nature and sunrise

Snowy Mountains

Step 1) Add HTML:

Example

The Woods

Cinque Terre

Mountains and fjords

Northern Lights

Nature and sunrise

Snowy Mountains

Step 2) Add CSS:

Style the image gallery, next and previous buttons, the caption text and the dots:

Example

/* Position the image container (needed to position the left and right arrows) */
.container position: relative;
>

/* Hide the images by default */
.mySlides display: none;
>

/* Add a pointer when hovering over the thumbnail images */
.cursor cursor: pointer;
>

/* Next & previous buttons */
.prev,
.next cursor: pointer;
position: absolute;
top: 40%;
width: auto;
padding: 16px;
margin-top: -50px;
color: white;
font-weight: bold;
font-size: 20px;
border-radius: 0 3px 3px 0;
user-select: none;
-webkit-user-select: none;
>

Читайте также:  Telegram php get message

/* Position the «next button» to the right */
.next right: 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);
>

/* Number text (1/3 etc) */
.numbertext color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
>

/* Container for image text */
.caption-container text-align: center;
background-color: #222;
padding: 2px 16px;
color: white;
>

.row:after content: «»;
display: table;
clear: both;
>

/* Six columns side by side */
.column float: left;
width: 16.66%;
>

/* Add a transparency effect for thumnbail images */
.demo opacity: 0.6;
>

Step 3) Add JavaScript:

Example

let 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) let i;
let slides = document.getElementsByClassName(«mySlides»);
let dots = document.getElementsByClassName(«demo»);
let captionText = document.getElementById(«caption»);
if (n > slides.length)
if (n < 1)
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»;
captionText.innerHTML = dots[slideIndex-1].alt;
>

Источник

Как сделать — Слайд-шоу

Узнать, как создать адаптивное слайд-шоу с помощью CSS и JavaScript.

Слайд-шоу / Карусель

Слайд-шоу используется для циклического перебора элементов:

Создание слайд-шоу

Шаг 1) Добавить HTML:

Пример

Шаг 2) Добавить CSS:

Стиль следующей и предыдущей кнопок, текста заголовка и точек:

Пример

/* Контейнер слайд-шоу */
.slideshow-container max-width: 1000px;
position: relative;
margin: auto;
>

/* Скрыть изображения по умолчанию */
.mySlides display: none;
>

/* Вперед иназад кнопки */
.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;
>

Читайте также:  Making games with python and pygame

/* Положение «next кнопки» справа */
.next right: 0;
border-radius: 3px 0 0 3px;
>

/* При наведении курсора добавьте черный цвет фона с немного прозрачным */
.prev:hover, .next:hover background-color: rgba(0,0,0,0.8);
>

/* Подпись текст */
.text color: #f2f2f2;
font-size: 15px;
padding: 8px 12px;
position: absolute;
bottom: 8px;
width: 100%;
text-align: center;
>

/* Номер текста (1/3 и т.д.) */
.numbertext color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
>

/* Точки/пули/индикаторы */
.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;
>

/* Исчезающая анимация */
.fade -webkit-animation-name: fade;
-webkit-animation-duration: 1.5s;
animation-name: fade;
animation-duration: 1.5s;
>

Шаг 3) Добавить JavaScript:

Пример

var slideIndex = 1;
showSlides(slideIndex);

// Вперед/назад элементы управления
function plusSlides(n) showSlides(slideIndex += n);
>

// Элементы управления миниатюрами изображений
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)
if (n < 1)
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»;
>

Автоматическое Слайд-шоу

Чтобы отобразить автоматическое слайд-шоу, используйте следующий код:

Пример

var slideIndex = 0;
showSlides();

function showSlides() var i;
var slides = document.getElementsByClassName(«mySlides»);
for (i = 0; i < slides.length; i++) slides[i].style.display = "none";
>
slideIndex++;
if (slideIndex > slides.length)
slides[slideIndex-1].style.display = «block»;
setTimeout(showSlides, 2000); // Меняйте изображение каждые 2 секунды
>

Несколько Слайд-шоу

Пример

var slideIndex = [1,1];
/* Класс чисел каждой группы слайд-шоу с различными классами CSS */
var slideId = [«mySlides1», «mySlides2»]
showSlides(1, 0);
showSlides(1, 1);

function plusSlides(n, no) showSlides(slideIndex[no] += n, no);
>

function showSlides(n, no) var i;
var x = document.getElementsByClassName(slideId[no]);
if (n > x.length)
if (n < 1)
for (i = 0; i < x.length; i++) x[i].style.display = "none";
>
x[slideIndex[no]-1].style.display = «block»;
>

Источник

Оцените статью