Jayr
Jayr

Reputation: 608

jquery / javascript Redefine function

Since I started this new webshop for a friend to launch, which still in progress, I'm using the so called "jQuery fixedScroll"..

Project online: http://www.merkversterkers.com/klanten/fragma/index.php?p=shop

Everything is fine until this.. When I'm using the scrollplugin, it defines the height of the page, which a good thing..

After pressing the "filter" button the height must be predefined causing a div that will expand, and I'm unable to do that, because the document defines the height when it's loaded..

like the "$(document).ready" function

scrollfunction

$('#scart').scrollToFixed({
   marginTop: $('.topbar').outerHeight() + 30,
   limit: get_limit(),
   zIndex: 999
});

get_limit functon

function get_limit(){
    var products_row = 4;

    var topbar = $(".topbar").height() + 30 
    var filterbar = $(".filterbar").height();
    var products = products_row * 206;

    if( $(".filterexpanded").css('display') == "block" ){
        var expanded = $(".filterexpanded").height(); 
    } else {
        var expanded = 0;
    }   

    var cartheight = $("#scart").height();

    var limit = topbar + filterbar + expanded + products + 130 - cartheight;

    return limit;
}

Can someone give me throw of some code I could try? I would really appreciate all the help..

Upvotes: 1

Views: 928

Answers (3)

bfavaretto
bfavaretto

Reputation: 71918

An (untested) idea after looking at the plugin's source:

var scrollToFixedObj = $('#scart').data("ScrollToFixed");
scrollToFixedObj.options.marginTop = get_limit();

Upvotes: 0

jcreamer898
jcreamer898

Reputation: 8189

When you are trying to set a function as a value in an object you should not use the parentheses. When you do, you are basically evaluating the function and it's value will be returned instead of the actual function.

var myObject = {
    myFunction: funkyFunk()
};

function funkyFunc(){
    var funkierFunction(){
        // You COULD do this
    };
    return funkierFunction;
}

But this is what you need...

var myObject = {
    myFunction: funkyFunk
};

function funkyFunc(){
    // You probably want this though    
}

Upvotes: 1

qwertymk
qwertymk

Reputation: 35276

Without reading the question you should change this:

limit: get_limit(),

To this:

limit: get_limit,

Upvotes: 1

Related Questions