I am using the following jquery script in a WordPress site. It works fine when I do not enqueue jQuery. However, when jQuery is enqueued, it no longer runs.
Any ideas what I am doing wrong?
$(function() {
var $sidebar = $(".side"),
$window = $(window),
offset = $sidebar.offset(),
topPadding = 15;
$window.scroll(function() {
if ($window.scrollTop() >= 240) {
$sidebar.stop().animate({
marginTop: $window.scrollTop() - offset.top + topPadding
});
} else {
$sidebar.stop().animate({
marginTop: 0
});
}
});
});
PS. Yes, I have tried changing the intial call from $(function)) to jquery(function)) but it still does not run.
You need to pass the
$symbol to the function:jQuery(function($){ })so you can use it within your code. Otherwise you need to replace every$in your code withjQuerySee: jQuery.noConflict()