how to show Image slider for long time - javascript

I am trying to show the image slider for long time where I already used timeout for every image to display.
But now I want to image slider in this case also:
1.The system should not go the sleep mode if we are not using the system, it
should show the image slider until I close the browser.
2.The system should not go to the screensaver mode, it should show the image
slider until I close the browser.
code:
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.mySlides
{
display:none;
}
</style>
<body>
<h2 class="w3-center"></h2>
<div class="w3-content w3-section" style=""width='962px';height='565px';frameborder='0'"">
<img class="mySlides" src="Chrysanthemum.jpg" style="width='100%">
<img class="mySlides" src="Desert.jpg" style="width:100%">
<img class="mySlides" src="Hydrangeas.jpg" style="width:100%">
</div>
<script>
var myIndex = 0;
carousel();
function carousel() {
var i;
var x = document.getElementsByClassName("mySlides");
for (i = 0; i < x.length; i++)
{
x[i].style.display = "none";
}
myIndex++;
if (myIndex > x.length)
{
myIndex = 1;
}
x[myIndex-1].style.display = "block";
setTimeout(carousel, 2000);
}
</script>
</body>
</html>

Related

W3 automatic slideshow 2 on same page

I need 2 automatic slideshow on one page, but there is a problem.
I use W3 slideshow, but if i make automatic they just after one rotation or just stop show up.
Here is code.
I try to change, but i not sure what i do wrong. If you can help me.
var myIndex = 0;
carousel();
var slideId = ["mySlides1", "mySlides2"]
function carousel() {
var i;
var x = document.getElementsByClassName("mySlides", "mySlides2");
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
myIndex++;
if (myIndex > x.length) {myIndex = 1}
x[myIndex-1].style.display = "block";
setTimeout(carousel, 2000); // Change image every 2 seconds
}
.mySlides {display:none;}
.mySlides2 {display:none;}
<!DOCTYPE html>
<html>
<head>
<title>W3.CSS</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta content="text/html; charset=iso-8859-2" http-equiv="Content-Type">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
</head>
<body>
<h2 class="w3-center">Automatic Slideshow</h2>
<div class="w3-content w3-section" style="max-width:500px">
<img class="mySlides" src="img_la.jpg" style="width:100%">
<img class="mySlides" src="img_ny.jpg" style="width:100%">
<img class="mySlides" src="img_chicago.jpg" style="width:100%">
</div>
<h2 class="w3-center">Automatic Slideshow</h2>
<div class="w3-content w3-section" style="max-width:500px">
<img class="mySlides2" src="img_la.jpg" style="width:100%">
<img class="mySlides2" src="img_ny.jpg" style="width:100%">
<img class="mySlides2" src="img_chicago.jpg" style="width:100%">
</div>
</body>
</html>
I made some edits and now your code is working !
You don't want to use only one index, you want to use one index for each slideshow.
For each call to carousel() you will need to stop displaying the current img (n°[x|y]Index), and display the next img (n°[x|y]Index).
With this function, you can add different numbers of images in each slideshow (in my example, mySlides displays 3 images and mySlides2 has 4).
let xIndex = 0;
let yIndex = 0;
carousel();
function carousel() {
let x = document.getElementsByClassName("mySlides");
let y = document.getElementsByClassName("mySlides2");
x[xIndex].style.display = "none";
y[yIndex].style.display = "none";
xIndex = (xIndex+1)%x.length;
yIndex = (yIndex+1)%y.length;
if (xIndex > x.length)
xIndex = 1;
if (yIndex > y.length)
yIndex = 1;
x[xIndex].style.display = "block";
y[yIndex].style.display = "block";
setTimeout(carousel, 2000); // Change image every 2 seconds
}
<h2>Automatic Slideshow</h2>
<div style="width:150px; height:150px; overflow: hidden;">
<img class="mySlides" src="http://lorempixel.com/400/400/" style="width:100%; display: none;">
<img class="mySlides" src="http://lorempixel.com/400/200/" style="width:100%; display: none;">
<img class="mySlides" src="http://lorempixel.com/200/400/" style="width:100%; display: none;">
</div>
<h2>Automatic Slideshow</h2>
<div style="width:150px; height:150px; overflow: hidden;">
<img class="mySlides2" src="http://lorempixel.com/400/300/" style="width:100%; display: none;">
<img class="mySlides2" src="http://lorempixel.com/300/400/" style="width:100%; display: none;">
<img class="mySlides2" src="http://lorempixel.com/300/300/" style="width:100%; display: none;">
<img class="mySlides2" src="http://lorempixel.com/800/300/" style="width:100%; display: none;">
</div>

HTML image slideshow shows a blank screen

I do not have much experience with html but I need to setup a image slideshow on my site. I found this bit of code on w3schools but after adding media query it shows a blank screen in between the images. How do i get rid of it and have just back to back images only? Thanks
<!DOCTYPE html>
<html>
<head>
<title>W3.CSS</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta content="text/html; charset=iso-8859-2" http-equiv="Content-Type">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<style>
.mySlides {display:none;}
#media only screen and (min-width: 480px) {
#web {
display: none;
}
}
#media only screen and (max-width: 480px) {
#mobile {
display: none;
}
}
</style>
</head>
<body>
<div class="w3-content w3-section" id="web">
<img class="mySlides" src="https://www.91-img.com/pictures/126849-v6-honor-10-mobile-phone-large-1.jpg" style="width:100%">
<img class="mySlides" src="https://static.toiimg.com/photo/64428999/Vivo-NEX.jpg" style="width:100%">
</div>
<div class="w3-content w3-section" id="mobile">
<img class="mySlides" src="https://japan-magazine.jnto.go.jp/jnto2wm/wp-content/uploads/1603_iwate_main.jpg" style="width:100%">
<img class="mySlides" src="https://image.shutterstock.com/image-photo/panoramic-view-idyllic-mountain-scenery-260nw-622792952.jpg" style="width:100%">
</div>
<script>
var myIndex = 1;
carousel();
function carousel() {
var i;
var x = document.getElementsByClassName("mySlides");
for (i = 1; i < x.length; i++) {
x[i].style.display = "none";
}
myIndex++;
if (myIndex > x.length) {myIndex = 1}
x[myIndex-1].style.display = "block";
setTimeout(carousel, 2000);
}
</script>
</body>
</html>
All indexes start with 0. So change initial index in your for loop to 0 and get it work. Also you have to change classNames for your images in the mobile version (it's why you got blank pages after a few images shown) and you implemented wrong media queries.
var myIndex = 0;
carousel();
function carousel() {
var i;
if(screen.width <= 480){
var x = document.getElementsByClassName("mySlides_mobile");
}else{
var x = document.getElementsByClassName("mySlides");
}
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
myIndex++;
if (myIndex > x.length) {myIndex = 1}
x[myIndex-1].style.display = "block";
setTimeout(carousel, 2000);
}
.mySlides, .mySlides_mobile {
display:none;
}
#media only screen and (max-width: 480px) {
#web {
display: none;
}
}
#media only screen and (min-width: 480px) {
#mobile {
display: none;
}
}
<!DOCTYPE html>
<html>
<head>
<title>W3.CSS</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta content="text/html; charset=iso-8859-2" http-equiv="Content-Type">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
</head>
<body>
<div class="w3-content w3-section" id="web">
<img class="mySlides" src="https://www.91-img.com/pictures/126849-v6-honor-10-mobile-phone-large-1.jpg" style="width:100%">
<img class="mySlides" src="https://static.toiimg.com/photo/64428999/Vivo-NEX.jpg" style="width:100%">
</div>
<div class="w3-content w3-section" id="mobile">
<img class="mySlides_mobile" src="https://japan-magazine.jnto.go.jp/jnto2wm/wp-content/uploads/1603_iwate_main.jpg" style="width:100%">
<img class="mySlides_mobile" src="https://image.shutterstock.com/image-photo/panoramic-view-idyllic-mountain-scenery-260nw-622792952.jpg" style="width:100%">
</div>
</body>
</html>

W3 slideshow implementation doesn't work correctly

https://www.w3schools.com/w3css/tryit.asp?filename=tryw3css_slideshow_fading
Using the link above, you can see an example of an animated fading slideshow that I am trying to implement into my website. However, when I copy the exact code and use it for me, it displays the images stacked on top of one another as one image, and just fades it in and out to the same image (made up of all of the images).
Any idea why this is happening or another source where I can get an animated slideshow from? The only other thing to take into account is that in the styles file, everything referring to 'webkit' is underlined in red. I am running in chrome though so I don't think that is the issue.
Here is the code:
<!DOCTYPE html>
<html>
<title>W3.CSS</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<body>
<div class="w3-content w3-section" style="max-width:500px">
<p>The w3-animate-fading class animates an element in and out (takes about 10 seconds).</p>
<img class="mySlides w3-animate-fading" src="../../assets/img/img_rr_01.jpg" style="width:100%" alt="image1">
<img class="mySlides w3-animate-fading" src="../../assets/img/img_rr_02.jpg" style="width:100%" alt="image2">
<img class="mySlides w3-animate-fading" src="../../assets/img/img_rr_03.jpg" style="width:100%" alt="image3">
<img class="mySlides w3-animate-fading" src="../../assets/img/img_rr_04.jpg" style="width:100%" alt="image4">
</div>
<script>
var myIndex = 0;
carousel();
function carousel() {
var i;
var x = document.getElementsByClassName("mySlides");
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
myIndex++;
if (myIndex > x.length) {myIndex = 1}
x[myIndex-1].style.display = "block";
setTimeout(carousel, 9000);
}
</script>
</body>
</html>
This is exactly the code on the website, and I downloaded the images they use, so why is it that I can't get it to work?
<!DOCTYPE html>
<html>
<title>W3.CSS</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<body>
<div class="w3-content w3-section" style="max-width:500px">
<p>The w3-animate-fading class animates an element in and out (takes about 10 seconds).</p>
<img class="mySlides w3-animate-fading" src="img_rr_01.jpg" style="width:100%" alt="image1">
<img class="mySlides w3-animate-fading" src="img_rr_02.jpg" style="width:100%" alt="image2">
<img class="mySlides w3-animate-fading" src="img_rr_03.jpg" style="width:100%" alt="image3">
<img class="mySlides w3-animate-fading" src="img_rr_04.jpg" style="width:100%" alt="image4">
</div>
<script>
var myIndex = 0;
carousel();
function carousel() {
var i;
var x = document.getElementsByClassName("mySlides");
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
myIndex++;
if (myIndex > x.length) {myIndex = 1}
x[myIndex-1].style.display = "block";
setTimeout(carousel, 9000);
}
</script>
</body>
</html>
Here its working correctly. It may me something else that would be causing some problem.

change speed of transition in scrolling sideshow

I found some code for a scrolling slideshow which I want to use and I figured out how to alter the duration of each slide as it comes to rest, but not how to change the duration of the actual transition (the part where the slide moves in and out. I have pasted the code here. Can someone tell me where in the js I need to change values? Also, can this same effect be achieved using just css, and if so, can someone explain how? Ideally I would like to use just css since I think it would be simpler and I am more familiar with it. Thank you.
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
body {
width: 960px;
margin: 0 auto 0;
}
</style>
</head>
<body>
<div class="w3-content w3-section" style="max-width:500px">
<img class="mySlides w3-animate-left" src="https://www.bartonlewis.com/_imagesfilm/23rd_st.jpg" alt="Mountain" style="width:100%">
<img class="mySlides w3-animate-left" src="https://www.bartonlewis.com/_imagesfilm/blue.jpg" style="width:100%">
<img class="mySlides w3-animate-left" src="https://www.bartonlewis.com/_imagesfilm/broken_guru.jpg" style="width:100%">
<img class="mySlides w3-animate-left" src="https://www.bartonlewis.com/_imagesfilm/church_ave.jpg" style="width:100%">
</div>
<script>
var myIndex = 0;
carousel();
function carousel() {
var i;
var x = document.getElementsByClassName("mySlides");
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
myIndex++;
if (myIndex > x.length) {myIndex = 1}
x[myIndex-1].style.display = "block";
setTimeout(carousel, 2500);
}
</script>
</body>
</html>
It looks like the actual fade/slide in transition effect is already being handled by CSS animations, via this style:
.w3-animate-left {
position: relative;
animation: animateleft 0.4s;
}
If you duplicate that style locally you should be able to override it and increase the duration, e.g. https://codepen.io/anon/pen/JrJeoB
in Javascript you need need to change,
setTimeout(carousel, 2500);
This Javascript function is actually Calling carousel
function every 2500 that is 2.5 Seconds.
you can increase/decrease your 2500 values which is 2.5 Seconds as you like .
And for 1 Seconds you need to change the value to 1000 .
and for css
you can USE . transition delay 2s

Why does my javascript code rotate big images (>1MB)?

Hello and thanks in advance!
I created with some help the following code to display images out of a folder in kind of a slideshow. every minute the side will reload itself if nobody did something. this is to display new images while the slideshow is running. if the uploaded image is small (<1MB) the slideshow displays everything fine. But do I upload or copy larger images the slideshow flips or rotates the image sometime 180' or 90'.
here is the code:
<?php
$dir_path = "uploads/prints/";
$extensions_array = array('jpg','png','jpeg');
if(is_dir($dir_path))
{
$files = array_slice(scandir($dir_path), 2);
foreach ($files as $file)
{
$ext = pathinfo($file);
$ext = $ext['extension'];
if(in_array($ext, $extensions_array))
$images[] = '<img class="mySlides" src="'. $dir_path . $file.'" style="max-width:90%";>';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>automatic slideshow</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<style>
.mySlides {display:none;}
</style>
</head>
<body background="/back2.png">
<!--<h2 class="w3-center">Automatic Slideshow</h2> -->
<div class="w3-content w3-section" style="width:500px">
<?php echo implode ($images); ?>
</div>
<script>
var myIndex = 0;
carousel();
function carousel() {
var i;
var x = document.getElementsByClassName("mySlides");
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
myIndex++;
if (myIndex > x.length) {myIndex = 1}
x[myIndex-1].style.display = "block";
setTimeout(carousel, 4000); // Change image every 4 seconds
}
//refresh page
var timeout = setTimeout("location.reload(true);",60000);
function resetTimeout() {
clearTimeout(timeout);
timeout = setTimeout("location.reload(true);",0000);
}
</script>
</body>
Does anyone has an idea?

Categories

Resources