Created
September 11, 2018 13:36
-
-
Save shaneonabike/209f32233980a78f8e0b814dacbd19c2 to your computer and use it in GitHub Desktop.
Popup 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
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