Instantly share code, notes, and snippets.
Last active
April 11, 2020 09:23
Super simple cookie banner solution
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
<div id="cookie"> | |
<div id="cookie-wrapper"> | |
<div id="cookie-content">Questo sito <em>potrebbe</em> usare i cookie</div> | |
<button id="cookie-ok">Ok</button> | |
</div> | |
</div> |
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($){ | |
$(document).ready(function() { | |
var consent = localStorage.getItem('cookie-consent'); | |
if(consent != 'true'){ | |
$('#cookie').fadeIn(); | |
} | |
$('#cookie-ok').click(function(event){ | |
localStorage.setItem('cookie-consent', 'true'); | |
$('#cookie').fadeOut(); | |
}); | |
}); | |
})(jQuery); |
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
#cookie{ | |
display: none; | |
position: fixed; | |
bottom: 2rem; | |
left: 50%; | |
transform: translateX(-50%); | |
background: #212529; | |
color: #dee2e6; | |
max-width: 90%; | |
z-index: 1090; | |
font-size: .8rem; | |
#cookie-wrapper{ | |
display: flex; | |
flex-direction: row; | |
padding: .6rem 0; | |
#cookie-content, | |
#cookie-ok{ | |
padding: 0 .6rem; | |
} | |
#cookie-content{ | |
border-right: 1px solid #dee2e6; | |
} | |
#cookie-ok{ | |
border: 0; | |
background: none; | |
color: inherit; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment