automatik-background-image-slider.php
Quell Code
<!DOCTYPE html>
<html>
<head>
<title>Welcome!</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
*{
margin:0px;
padding:0px;
}
body{
overflow:hidden;
height:100vh;
width:100vw;
}
.SlideBox{
height:100%;
width:100%;
background-color:rgba(16,32,128,0.1);
background-repeat:no-repeat;
}
</style>
</head>
<body>
<div class="SlideBox">
</div>
<script>
var myIndex = 0;
var timer;
carousel();
timer=setInterval(carousel, 5000);
var bod=document.getElementsByTagName('body')[0];
bod.addEventListener('mousedown',function(){
clearInterval(timer);
carousel();
})
bod.addEventListener('mouseup',function(){
timer=setInterval(carousel, 5000);
})
function carousel() {
var x=['/bilder/1.png','/bilder/2.png','/bilder/3.png','/bilder/4.png','/bilder/5.png','/bilder/6.png','/bilder/11.png'];
myIndex++;
if (myIndex > x.length) {myIndex = 1}
var box=document.getElementsByClassName("SlideBox")[0];
box.style.background='url('+x[myIndex-1]+')';
box.style.backgroundSize='contain';
box.style.backgroundPosition='center center';
box.style.backgroundRepeat='no-repeat';
}
</script>
</body>
</html>