Guest User

Untitled

a guest
Aug 17th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>Background changer</title>
  4. <meta charset="utf-8"/>
  5. <style type="text/css">
  6. body {
  7. margin: 0;
  8. }
  9. #background {
  10. transition-property: background;
  11. transition-duration: 5000ms;
  12. transition-timing-function : linear ;
  13. z-index: -100;
  14. position: absolute;
  15. margin: 0;
  16. background : url(https://i.imgur.com/6IjDFqg.jpg);
  17. }
  18. </style>
  19. </head>
  20. <body>
  21. <div id="background"></div>
  22. <button onclick="chback(0)">Background 1</button><br/>
  23. <button onclick="chback(1)">Background 2</button><br/>
  24. <button onclick="chback(2)">Background 3</button><br/>
  25. </body>
  26. <script type="text/javascript">
  27. img = [
  28. 'https://i.imgur.com/6IjDFqg.jpg',
  29. 'https://i.imgur.com/Ai5Zbq1.jpg',
  30. 'https://i.imgur.com/9jHOYe9.jpg',
  31. ];
  32. back = document. getElementById ('background');
  33. back . style . width = document . documentElement . clientWidth ;
  34. back . style . height = document . documentElement . clientHeight ;
  35. function chback ( n ) {
  36. back . style . background = `url(${ img [ n ]}})`;
  37. }
  38. </script>
  39. </html>
Advertisement
Add Comment
Please, Sign In to add comment