Instantly share code, notes, and snippets.

Embed
What would you like to do?
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