Skip to content

Instantly share code, notes, and snippets.

@shaneonabike
Created September 11, 2018 13:36
Show Gist options
  • Save shaneonabike/209f32233980a78f8e0b814dacbd19c2 to your computer and use it in GitHub Desktop.
Save shaneonabike/209f32233980a78f8e0b814dacbd19c2 to your computer and use it in GitHub Desktop.
Popup JS
jQuery(function($) {
// Scroll the popup with the user
$(window).scroll(function() {
var windowWidth = document.documentElement.clientWidth;
var windowHeight = document.documentElement.clientHeight;
var popupWidth = $("#likeus").width();
var popupHeight = $("#likeus").height();
var topPopup = windowHeight * 2 / 3 + $(window).scrollTop();
var leftPopup = windowWidth - popupWidth;
// Did they say permanently
if (!$.cookie('likeus-popup')){
if (($('#likeus').css('display') == 'none') && ($('body').height() / 2 + popupHeight) <= ($(window).height() + $(window).scrollTop()+popupHeight*2)) {
$('#likeus').animate({top:topPopup, left:leftPopup},60);
$('#likeus').slideDown();
}
else if ($('#likeus').css('display') != 'none') {
$('#likeus').animate({top:topPopup, left:leftPopup},60);
}
}
});
// Regular close button clicked
$("a.close-like").click(function(){
$('#likeus').slideUp();
$('#likeus').attr("id", "likeus-hide");
return false;
});
// They already like us so close it permanently
$("a.close-forever").click(function() {
$('#likeus').slideUp();
$('#likeus').attr("id", "likeus-hide");
var date = new Date();
date.setDate(date.getDate() + 20*365);
$.cookie('likeus-popup', true, { expires: date });
return false;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment