Can someone demystify this line for me?
It’s javascript and it works fine, I just don’t understand the exact logic behind the code. Maybe it would help to split the code into several lines or write it in c# or delphi for “comparison”.
(I got it from here: http://www.learningjquery.com/2009/02/slide-elements-in-different-directions)
many thanks!
$('#inlay-container').animate(
{
left: parseInt($('#container').css('left'),10) == 0 ? +$('#container').outerWidth() : 0
}...
$('#container').css('left')get theleftposition of#containerset byCSS.parseInt($('#container').css('left'),10)convert to integer thatleft.Now you should know about ternary operator
--- ? --- : ---:General if-else:
In ternary it written as:
So
?act asifand:act aselse.$('#container').outerWidth()get the width of#containerincludingpaddingandborder.So therefore,
So above condition can also be written as
At last, whole statement can be written as
Related refs:
Ternary operator
.css()
.outerWidth()