I was looking at this code and had a few questions. I did some digging in a jquery fundamentals manual and on google but didn’t find a straightforward answer.
this is the full code
function slideSwitch()
{
var $active = $('#slideshow IMG.active');
if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
var $next = $active.next().length ? $active.next()
: $('#slideshow IMG:first');
$active.addClass('last-active');
$next.css({opacity: 0.0})
.addClass('active')
.animate({opacity: 1.0}, 1000, function() {
$active.removeClass('active last-active');
});
}
The first thing that strikes me is that he makes an inline if statement w/o brackets, that’s cool and I didn’t know you could do that. However, is it something that follows good coding standards or does it not matter?
Also the next line where he declares var $next. I’ve never seen a variable with those kinds of conditions in it. I’m guessing that he’s saying either input $active.next() and if the length is 0 than $active.next() is going to be the first img in the slide show. I’m not quite sure what the operands mean.
any insight?
I think you mean braces
{}.It is generally considered to be poor code style. It is too easy to come along later to add some more code to an
ifbranch and not realise that the brace-less syntax was used.JSLint will complain about that.
That’s a conditional (ternary) operator.
is equivalent to:
All of this is JavaScript. It has nothing to do with the jQuery library.