Skip to content

Instantly share code, notes, and snippets.

@oguzhanoptimum7
Last active February 21, 2022 11:35
Show Gist options
  • Save oguzhanoptimum7/d1b7faf7d143511ba19ac86d6c6f970c to your computer and use it in GitHub Desktop.
Save oguzhanoptimum7/d1b7faf7d143511ba19ac86d6c6f970c to your computer and use it in GitHub Desktop.
blue-cookie-set
<script>
function setCookie(name,value,days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/";
}
function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name) {
document.cookie = name +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}
$(function(){
jQuery(window).resize(function() {
let is_closed = false;
if(getCookie('scrolled') === "yes"){
is_closed = true;
}else{
is_closed = false;
}
if (jQuery(window).width() < 480) {
jQuery(document).scroll(function() {
var y = jQuery(this).scrollTop();
if (y > 1200 && !is_closed) {
jQuery('#sidebar').fadeIn();
jQuery('.toggle').fadeIn();
} else {
jQuery('#sidebar').fadeOut();
jQuery('.toggle').fadeOut();
}
jQuery(".toggle").click(function() {
is_closed = !is_closed;
jQuery("#sidebar").hide();
if(getCookie('scrolled')){
setCookie("scrolled","no",7);
}else{
setCookie("scrolled","yes",7);
}
});
});
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment