I was wondering whether it is possible to set a property inside jQuery’s animate based on some criteria. Example:
var condition = offL > ((wW / 2) - $this.width());
tooltip.css(function() {
if (condition) {
return '"right", "auto"';
} else {
return '"left", "auto"';
}
}).animate({
"top": $this.offset().top + (posT / 2) - (tooltip.height() / 2),
if (condition) {
return '"left":"offL - tooltip.width() - 30"';
} else {
return '"right", "offR - tooltip.width() - 30"';
}
}, 300).fadeTo(200, 1);
(tooltip and other vars are defined earlier.)
This does not work, obviously. But, how would one go about if they need to use conditional arguments inside functions?
Another side question, is my usage of my condition as a var correct?
Simply made the decision before the animation.
for exampaple:
and yes, your usage of condition is correct.
will be evaluated to true or false since its a condition 😉