A Pen by Jorge Reyes on CodePen.
Created
December 15, 2019 21:41
-
-
Save Nemra1/66b864118170624e69b0665d7006f9a8 to your computer and use it in GitHub Desktop.
Like Button with JS
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
<script defer src="https://use.fontawesome.com/releases/v5.6.3/js/all.js" integrity="sha384-EIHISlAOj4zgYieurP0SdoiBYfGJKkgWedPHH4jCzpCXLmzVsw1ouK59MuUtP4a1" crossorigin="anonymous"></script> | |
<!-- Scripts and Links --> | |
<div class="container"> | |
<h1> Press "L" to like this</h1> | |
<svg class="ico" width="24" height="24" viewBox="0 0 24 24"> | |
<path d="M12,21.35L10.55,20.03C5.4,15.36 2,12.27 2,8.5C2,5.41 4.42,3 7.5,3C9.24,3 10.91,3.81 12,5.08C13.09,3.81 14.76,3 16.5,3C19.58,3 22,5.41 22,8.5C22,12.27 18.6,15.36 13.45,20.03L12,21.35Z"></path> | |
</svg> | |
<div class="div"> | |
</div> | |
</div> | |
<!-- Logo and Footer --> | |
<div class="profile"> | |
<i class="fab fa-codepen" id="codepen"></i> | |
<p class="author"><a href="https://codepen.io/jorgert1205/#" target="_blank">/Jorgert1205</a></p> | |
</div> | |
<footer class="footer"> | |
This pen was made by <span><a href="https://reyesj.netlify.com/" target="_blank">Jorge Reyes</a></span>. | |
</footer> |
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
var likeBtn = document.querySelector('.ico'); | |
likeBtn.addEventListener('click', function() { | |
likeBtn.classList.toggle('liked'); | |
}); | |
document.addEventListener('keydown', function(key){ | |
if(key.key === 'l' || key.key === 'L') { | |
likeBtn.classList.toggle('liked'); | |
} | |
}); |
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
@import url('https://fonts.googleapis.com/css?family=Lato:300,400,700'); | |
body { | |
background-color: #ecf0f1; | |
font-family: 'Lato', sans-serif; | |
overflow: hidden; | |
background-image: url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="4" height="4" viewBox="0 0 4 4"%3E%3Cpath fill="%239C92AC" fill-opacity="0.4" d="M1 3h1v1H1V3zm2-2h1v1H3V1z"%3E%3C/path%3E%3C/svg%3E'); | |
} | |
.container { | |
display: flex; | |
flex-direction: column; | |
justify-content: center; | |
align-items: center; | |
width: 100%; | |
height: 90vh; | |
} | |
//////////////////// | |
.ico { | |
border-radius: 50%; | |
cursor: pointer; | |
fill: #232323; | |
transition: .4s; | |
} | |
.liked { | |
transform: scale(1.05) rotate(360deg); | |
background-color: #C62828; | |
padding: .8rem; | |
fill: white; | |
} | |
////////-FOOTER AND LOGO-//////////// | |
.profile { | |
color: #555; | |
position: absolute; | |
top: .5rem; | |
left: 1.5rem; | |
display: flex; | |
align-items: center; | |
font-size: 1rem; | |
.fa-codepen { | |
margin-right: .5rem; | |
} | |
.author { | |
a:link, | |
a:visited { | |
color: inherit; | |
text-transform: uppercase; | |
font-weight: 300; | |
text-decoration: none; | |
} | |
} | |
} | |
.footer { | |
height: 10vh; | |
width: 100%; | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
border-top: 1px solid #cdd1d6; | |
background-color: #dee1e5; | |
font-weight: 300; | |
color: #555; | |
position: relative; | |
span { | |
margin-left: 2px; | |
font-weight: 400; | |
cursor: pointer; | |
a:link, | |
a:visited { | |
color: currentColor; | |
text-decoration: none; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment