Problem with a code, Hope you can help me with that
-
Hi
I copy this code from the wpbeginner site:
jQuery(document).ready(function($) {
/**
* Configuration
* The container for your sidebar e.g. aside, #sidebar etc.
*/var sidebarElement = $(‘div#secondary’);
// 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 -100;// Hide the last widget
$(lastWidget).hide();// Check if user scroll have reached the top of the last widget and display it
$(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’).addClass(‘wpbstickywidget’);
widgetDisplayed = true;
}
}
});
}
});The code didnt work and the inspect element tool informed me that:
“Uncaught TypeError: Cannot read property ‘top’ of undefined”.The problem is in line 17.
Can you guys tell me how to fix the issue?
Thank you
- The topic ‘Problem with a code, Hope you can help me with that’ is closed to new replies.