0

Hello, I learning javascript and trying to reverse engineer something I found on a site to understand it.

Here is a link to the full script... http://jsfiddle.net/WHQKA/

I have gotten to understand most of it so I know what is going on and can learn from it.
However this line it confusing to me and I can not find any reference information. I am hoping that someone can simply explain it so I can grow.

$('.top:first').stop().animate({
    'left': (direction === 0) ? '-100%' : '100%' // I don't understand the infor after the colon :
},400);

So, I want to understand the direction and the negative and positve after that.

Many Thanks!
Tim

3
Contributors
3
Replies
24
Views
4 Years
Discussion Span
Last Post by lambing
1

I assume you're asking about the ternary operator. This:

'left': (direction === 0) ? '-100%' : '100%'

Is roughly equivalent to this:

if (direction === 0) {
    'left': '-100%';
}
else {
    'left': '100%';
}

So it's just a expressionized version of an if..else statement.

Edited by deceptikon

0

Great! Thank you for the help. Still learning and understanding.
Appreciate your help!

0

In addition, that is a ternary operator in JavaScript, just want to let you know. It saves a lot of lines by the way.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.