Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript stripped down slider for customizing Re: stripped down slider for customizing

#102200
seanroberts
Member

Yes they are using the same idea with current but use the “show” class instead.

To answer your question about why, even if the class is set to “current” and not “show”, it still works is simple.

It’s all in their first line of the gallery() function:



//this is their line
var current = ($('ul.slideshow li.show')? $('ul.slideshow li.show') : $('#ul.slideshow li:first'));



//that line is the simplified version of this

if ( $('ul.slideshow li.show') ) {

var current = $('ul.slideshow li.show');

}else {

var current = $('#ul.slideshow li:first')
}

So their code is saying, “Ok does a li with a class of ‘show’ exist inside a ul with a class of ‘slideshow’? If so, set our variable current to that object. If there is no such element, then make the variable current equal to the first li inside a ul with a class of ‘slideshow’.”

Does that make since? So since it is not looking for the “current” class we mentioned in previous posts, then it doesn’t care about it at all. All it cares about is a li with a class of ‘show’ and if it can’t find it, it defaults to the first li.

You may notice that if you add the show class to an image, that image will be the first in the slideshow.

As far as the efficiency, you do not need to worry about it at this point. This code looks fine and if you worry about efficiency too early in your development, you will usually make your code hard to read and maintain in the long run. Just get what your task done first, then look for ways to improve it. That is a lesson most programmers (and others) learn the hard way.