Last active
August 29, 2015 14:02
-
-
Save n7studios/c5785a89a5f64460d03a to your computer and use it in GitHub Desktop.
WordPress: Fade in last sidebar widget
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(document).ready(function($) { | |
/** | |
* Configuration | |
* The container for your sidebar e.g. aside, #sidebar etc. | |
*/ | |
var sidebarElement = $('div#secondary'); | |
// End config | |
// Check if the sidebar exists | |
if ($(sidebarElement).length > 0) { | |
// Get the last widget in the sidebar, and its position on screen | |
var widgetDisplayed = false; | |
var lastWidget = $('.widget:last-child', $(sidebarElement)); | |
var lastWidgetOffset = $(lastWidget).offset().top; | |
// Hide the last widget | |
$(lastWidget).hide(); | |
// When the user scrolls, check if we have reached the top of the last widget | |
// If we have, display the widget | |
$(document).scroll(function() { | |
// If the widget has been displayed, we don't need to keep doing | |
// a check. | |
if (!widgetDisplayed) { | |
if($(this).scrollTop() > lastWidgetOffset) { | |
$(lastWidget).fadeIn('slow'); | |
widgetDisplayed = true; | |
} | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment