Edit 3/02/12: Found another solution that worked by itself without the need for any other functions; see my own answer below.
I just don't see what's wrong here and have had no luck with the answers to all the other questions titled "SyntaxError: Expected token '}'"
I'm working with a sticky div function that keeps <div class="sticky"> always visible on window scroll.
jQuery 1.7.1 is included by WordPress and loads before the two functions below. All functions load, according to Dev Tools.
A <div class="sticky">with various html</div> is placed just about the </body> tag.
But I get a SyntaxError: Expected token '}' error.
This is in header:
$(document).ready(function(){
$('.sticky').jsticky({
marginTop: 0,
});
This main function is included above it:
(function($){
$.fn.extend({
//plugin name - jsticky
jsticky: function(options) {
//Settings list and the default values
var defaults = {
marginTop: 0
};
var options = $.extend(defaults, options);
return this.each(function() {
var o = options;
//Assign current element to variable, in this case is UL element
var obj = $(this);
var offset = obj.offset();
var topOffset = offset.top;
var marginTop = obj.css("marginTop");
var marginTopNum = parseInt(marginTop);
var diff = topOffset - marginTopNum;
var offset = obj.offset();
var topOffset = offset.top;
var leftOffset = offset.left;
var marginTop = obj.css("marginTop");
var marginLeft = obj.css("marginLeft");
$(window).scroll(function() {
var WindowScrollTop = $(window).scrollTop();
var scrollTop = WindowScrollTop + o.marginTop;
if (scrollTop >= topOffset){
obj.css({
marginTop: o.marginTop,
marginLeft: leftOffset,
position: 'fixed'
});
}
if (scrollTop < topOffset){
obj.css({
marginTop: marginTop,
marginLeft: marginLeft,
position: 'relative'
});
}
});
});
}
});
})(jQuery);