Frage

How to pass a variable into a method, here specifically the position(). All their examples use strings of fixed values.

I have two variables (varHorizontal, varVertical) both integers

$(this).position({
    "my": "center center",
    "at": varHorizontal varVertical,
    //also tried "at": varHorizontal+'px' varVertical+'px', 
    "of": $('#parentDiv')
}); 

I have looked for syntax rules and i have tried various combinations with '' etc, but no luck.

How can I pass variables into the method?

War es hilfreich?

Lösung

You need to concatenate them as a single string:

"at": varHorizontal + ' ' + varVertical,

Andere Tipps

Use Array like this:

"at": [varHorizontal , varVertical],
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top