Created
September 29, 2018 10:14
-
-
Save thejungwon/6c525d36451bac5e7d84cfd71eb95889 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function newimage(keyword){ | |
if(!ACCESS_KEY){ | |
alert("Please update your access key"); | |
return; | |
} | |
var url = `https://api.unsplash.com/search/photos?query=${keyword}&per_page=20&orientation=landscape&client_id=${ACCESS_KEY}`; | |
$.get(url,function(data){ | |
var picture = data.results[0]; | |
var picture_url = picture.urls.raw; | |
var photo_by_name = picture.user.name; | |
var photo_by_url = picture.user.links.html; | |
setCookie("picture",picture_url,0.5); | |
setCookie("photo-by-name",photo_by_name,0.5); | |
setCookie("photo-by-url",photo_by_url,0.5); | |
$('.interest-text').html(keyword); | |
$('.photoby').html(photo_by_name); | |
$('.photoby').attr('href',photo_by_url); | |
$('body').css('background-image',`url(${picture_url})`); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment