在 :nth-child( X ) 中插入 VAL 不起作用
为什么我不能在底部使用 SlideNumber...? 我尝试将 var SlideNumber = 3;
更改为 SlideNumber = 3;
但说实话,我在黑暗中摸索。
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;
}
});
先感谢您。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要添加,您可以使用
.eq
来避免串联并稍微提高性能 过滤方法(采用从零开始的索引):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):要将
SlideNumber
变量连接到选择器中,您需要分解字符串并将变量夹在+
运算符之间:否则,您的伪类选择器将简单地显示为字符串
":nth-child(SlideNumber)"
这并不完全符合您的意图。To concatenate your
SlideNumber
variable into your selector, you need to break up your string and sandwich your variable between+
operators:Otherwise your pseudo-class selector will simply appear as the string
":nth-child(SlideNumber)"
which isn't quite what you intend.