Skip to content

Instantly share code, notes, and snippets.

@mattkruskamp
Created July 13, 2012 00:03
Show Gist options
  • Save mattkruskamp/3101940 to your computer and use it in GitHub Desktop.
Save mattkruskamp/3101940 to your computer and use it in GitHub Desktop.
JavaScript for Pinterest-Style Popup
$(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