1

How do I get the variable "theOffset" to work inside the "localScroll" function. This is my non-working code:

jQuery(function( $ ){
    //initialize variable "theOffset"
    theOffset = 10; // <-- sets variable for inside of "localScroll" function

        $(window).resize(function() {
            theOffset = 20; // <-- does NOT reset inside "localScroll" function
        }); // end of window resize


    $.localScroll({
            target: '#content', 
            duration:1500,
            hash:true,
            offset: {top:0, left: theOffset}, // <-- I want to reset this on window resize 
            onBefore:function( e, anchor, $target ){
            },
            onAfter:function( anchor, settings ){
            }
    });
});
3
  • 4
    should put var before any variables you don't want to be in global scope. Commented Nov 18, 2010 at 22:38
  • you can edit your existing question stackoverflow.com/questions/4219478/… with new details, no need to start new question on the same issue.. Commented Nov 18, 2010 at 22:40
  • aaahh. I'm still learning the ways of stackoverflow. Commented Nov 18, 2010 at 22:45

1 Answer 1

1

A couple of pointers:

Your creating objects with all those {}. Though it may look like simple functions, they aren't.

offset is a property of the object being passed to $.localScroll

One thought is to make the object (which is passed to $.localScroll) outside of $.localScroll, set it to a variable, and reference that variable.

Not sure if this will work as is, may have to jump through a hoop or two still.

Something along the lines of:

var theOffset = {
...
offset: {top:0, left: whatever},
...
};

$(window).resize(function() {
theOffset.offset = 20;
});

$.localScroll(theOffset);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.