localStorage циклическая смена фона
Sergei-b84,
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style>.bg-image{
width: 100px;
height: 100px;
background-size: 100%;
background-repeat: no-repeat;
}
.bg-image.bg1{background-image:url('http://javascript.ru/forum/images/smilies/smile.gif')}
.bg-image.bg2{background-image:url('http://javascript.ru/forum/images/smilies/victory.gif')}
.bg-image.bg3{background-image:url('http://javascript.ru/forum/images/smilies/cray.gif')}
</style>
<script>
window.onload = function() {
var image = document.querySelector('.bg-image')
var x = +localStorage.x || 0;
image.classList.add('bg'+(x +1));
localStorage.x = ++x % 3
}
</script>
</head>
<body>
<div class="bg-image "></div>
</body>
</html>
Последний раз редактировалось рони, 23.05.2015 в 13:00.
|