Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>Wallpaper</title>
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
- <style>
- * {
- margin: 0;
- padding: 0;
- }
- body {
- background-color: #fff;
- text-align: center;
- }
- .container {
- transition: .4s;
- margin: 0 auto;
- background-color: #F5F5F5;
- width: 800px;
- height: 600px;
- position: relative;
- top: 47.5%;
- transform: translateY(-50%);
- text-align: center;
- border-radius: 8px;
- box-shadow: 2px 2px 18px 2px rgba(0,0,0, .75);
- }
- .container:hover {
- transition: .4s;
- box-shadow: 2px 2px 40px 2px rgba(0,0,0, .75);
- }
- .container img {
- width: 800px;
- height: 600px;
- position: absolute;
- left: 0px;
- top: 0px;
- display: block;
- border-radius: 8px;
- }
- .container img:empty {
- display: none;
- }
- .btn{
- transition: .4s ease-out;
- margin-top: 5px;
- padding: 5px;
- font-size: 1.3em;
- outline: none;
- color: #000;
- border: none;
- box-decoration-break: unset;
- background-color: transparent;
- }
- .btn:hover {
- transition: .6s ease-in-out;
- color: dodgerblue;
- }
- .fa-spinner {
- animation-name: loading;
- animation-duration: .5s;
- font-size: 36px;
- position: relative;
- top: 50%;
- animation-iteration-count: infinite;
- z-index: 999;
- display: none;
- color: #fff;
- text-shadow: 1px 2px #000;
- }
- @keyframes loading {
- to {
- transform: rotate(360deg);
- }
- }
- </style>
- </head>
- <body>
- <button id="myButton" class="btn"><i class="fa fa-image"></i></button>
- <a id="downloadButton" href="#" download>
- <button class="btn">
- <i class="fa fa-download"></i>
- </button>
- </a>
- <div class="container">
- <i id="loadingProgress" class="fa fa-spinner"></i>
- <img id="myWallpaper" src="">
- </div>
- <script>
- function generateImage () {
- var loading = document.getElementById('loadingProgress');
- const xhr = new XMLHttpRequest();
- const url = 'https://api.desktoppr.co/1/wallpapers';
- // Handling request
- xhr.responseType = 'json';
- xhr.onreadystatechange = function () {
- if (xhr.readyState === XMLHttpRequest.DONE) {
- var images = xhr.response.response;
- var randomNumber = Math.floor(Math.random() * 19);
- var wallpaper = document.getElementById('myWallpaper');
- var image = images[randomNumber].image.url;
- wallpaper.src = image;
- loading.style.display = 'none';
- wallpaper.style.display = 'block';
- } else {
- loading.style.display = 'block';
- }
- }
- // Sending request
- xhr.open('GET', url);
- xhr.send();
- }
- function downloadImage (element) {
- var image = document.getElementById('myWallpaper');
- element.setAttribute('href', image.src);
- console.log(element);
- }
- var generateBtn = document.getElementById('myButton');
- generateBtn.addEventListener('click', generateImage);
- var downloadBtn = document.getElementById('downloadButton');
- downloadBtn.addEventListener('click', function () {
- downloadImage(this);
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement