Pregunta

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?

¿Fue útil?

Solución

You need to concatenate them as a single string:

"at": varHorizontal + ' ' + varVertical,

Otros consejos

Use Array like this:

"at": [varHorizontal , varVertical],
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top