Why can't I use SlideNumber in the bottom...??
I tried to change var SlideNumber = 3;
to SlideNumber = 3;
but honestly, I'm fumbling in the dark.
if(window.location.hash != '') {
var SlideNumber = 3;
$('.slideshow').cycle({
fx: 'blindY', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
speed: 700,
cleartype: 1,
开发者_开发百科 startingSlide: $(window.location.hash).index(),
timeout: 3000,
after: function(curr,next,opts) {
$("#menu ul li:nth-child(SlideNumber)").addClass("active");
ready = true;
}
});
Thank you in advance.
To add, you can avoid concatenation and crank up the performance a bit by using the .eq
filtering method (which takes a zero-based index):
$("#menu ul li").eq(slideNumber-1).addClass("active");
To concatenate your SlideNumber
variable into your selector, you need to break up your string and sandwich your variable between +
operators:
$("#menu ul li:nth-child(" + SlideNumber + ")").addClass("active");
Otherwise your pseudo-class selector will simply appear as the string ":nth-child(SlideNumber)"
which isn't quite what you intend.
精彩评论