Менять background-image каждые 2 секунды
Подскажите пожалуйста скрипт который будет менять background-image каждые 2 секунды,или будет перебирать массив с изображениями и вставлять их в background images каждые 2 сек
|
Sergey_Koval,
http://javascript.ru/forum/dom-windo...tml#post430409 |
О, нашёл то, что искал, спасибо рони. Поставил 30 секунд, по-моему идеально значение))
|
<html>
<head>
<style>
body{
transition: 2s;
}
</style>
</head>
<body>
<script>
setInterval(()=> document.body.style.backgroundColor= '#'+Math.floor(Math.random() * 4095).toString(16), 2000);
</script>
</body>
</html>
|
j0hnik,
setInterval зло :) Math.floor(Math.random() * 4095).toString(16) не корректно без дополнения до 3 знаков. |
Может кому пригодится
<html>
<head>
<style>
body{
transition: 2s;
}
</style>
</head>
<body>
<script>
(bgc =()=> {
document.body.style.backgroundColor= '#'+Math.random().toString(16).slice(2,8);
setTimeout(bgc, 2000);
})();
</script>
</body>
</html>
|
| Часовой пояс GMT +3, время: 00:06. |