Skip to content

Instantly share code, notes, and snippets.

@laustdeleuran
Created September 11, 2012 13:51
Show Gist options
  • Save laustdeleuran/3698641 to your computer and use it in GitHub Desktop.
Save laustdeleuran/3698641 to your computer and use it in GitHub Desktop.
Resize repaint pattern
(function(){
var $content = $site.find('.site-content'),
lastSeenHeight = -1,
lastSeenWidth = -1,
lastSeenContentHeight = -1,
$win = $(window);
$win.smartresize(function(){
var winHeight = $win.height(),
winWidth = $win.width();
// Avoid unecessary repaints if no real change has occured to window size
if (winHeight === lastSeenHeight && winWidth === lastSeenWidth) return;
lastSeenHeightlastSeenWidth = winWidth;
lastSeenHeight = winHeight;
// Avoid unecessary repaints if no real change has occured to content size
var newContentHeight = $content.outerHeight();
if (lastSeenContentHeight === newContentHeight) return;
lastSeenContentHeight = newContentHeight;
// Now do changes
$content.css('background','#f0f');
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment