Created
July 13, 2012 00:03
-
-
Save mattkruskamp/3101940 to your computer and use it in GitHub Desktop.
JavaScript for Pinterest-Style Popup
This file contains hidden or 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
$(document).ready(function () { | |
var clickableLink = $('a'), | |
container = $('.container'), | |
popup = $('.popup'), | |
body = $('body'), | |
activePosition = 0, | |
popupActive = false, | |
win = $(window); | |
clickableLink.click(function (e) { | |
e.preventDefault(); | |
e.stopPropagation(); | |
var position = win.scrollTop(); | |
// set the location of the scrolling | |
container.css('top', -position + 'px'); | |
activePosition = position; | |
// set the window to the top | |
win.scrollTop(0); | |
// add popup styling | |
container.addClass('active'); | |
popup.addClass('active'); | |
popupActive = true; | |
}); | |
// called if the popup is active | |
body.click(function (e) { | |
if (!popupActive) | |
return false; | |
// remove styling | |
container.removeClass('active'); | |
popup.removeClass('active'); | |
popupActive = false; | |
// move the container and the scroller back | |
container.css('top', '0px'); | |
win.scrollTop(activePosition); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment