我想通过基于现有的开放源代码在网上做我自己的jQuery幻灯片来学习。什么是这个幻灯片代码更可读的版本?
我迷失在一个编码块中,我认为这主要是因为我在编程/ jQuery中不是很强壮,而且编写它的人使用了一堆三元运算符(我相信这就是这是)。
有人可以帮我解决这个问题,甚至可以用更多的“传统”操作员来取代三元操作员吗?
//if no IMGs have the show class, grab the first image
var current = ($('ul.slideshow li.show') ? $('ul.slideshow li.show') : $('#ul.slideshow li:first'));
//Get next image, if it reached the end of the slideshow, rotate it back to the first image
var next = ((current.next().length) ? ((current.next().attr('id') == 'slideshow-caption') ? $('ul.slideshow li:first') :current.next()) : $('ul.slideshow li:first'));
我对最后一行感到困惑。
+1 - 打我吧! – 2011-03-17 20:03:15
好的,请原谅我,如果我得到太具体,但我再次努力学习。我把“alert(current.next()。length);”上面,它一直提醒“1”。我认为这个长度是想告诉我有多少元素匹配选择器?你能告诉我上面多长时间吗? – Stefan 2011-03-17 21:38:40
以及在中心:“next = current.next();”你介意告诉我current.next()在做什么?我又一次认为next()被用来选择下一个元素? – Stefan 2011-03-17 21:42:21