문제

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?

도움이 되었습니까?

해결책

You need to concatenate them as a single string:

"at": varHorizontal + ' ' + varVertical,

다른 팁

Use Array like this:

"at": [varHorizontal , varVertical],
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top