将 jquery 属性应用到另一个 div
我正在使用 jquery 滑块,它会自动生成具有以下 html 输出的分页项目符号:
<ul class="pagination">
<li class="current"><a href="#0">1</a></li>
<li><a href="#1">2</a></li>
<li><a href="#2">3</a></li>
<li><a href="#3">4</a></li>
</ul>
您可以在 http://pixelcakecreative 中查看此示例.com/
当您单击以下锚链接之一时,我希望能够重置幻灯片位置(将其设置回第一张幻灯片):
<li><a href="#" rel="#panel-1" class="activeSlide pita">Trendz<div class="buttonFade"></div></a></li>
<li><a href="#" class="pita" rel="#panel-2">Decibel<div class="buttonFade"></div></a></li>
<li><a href="#" class="pita" rel="#panel-3">UCC<div class="buttonFade"></div></a></li>
滑块实际上是 div 内的 3 个滑块,可切换其位置基于任何锚点(上面的代码)被点击。所以基本上,当您单击切换项目滑块的任何链接时,我想返回到滑块的第一个图像。
我尝试过,但没有运气,知道如何做到这一点吗?
我将使用我现有的代码来启动 jquery,用于单击触发链接之一:
$('#pixel-slider ul a.pita').click(function () {
$('#pixel-slider ul a').removeClass('activeSlide');
$(this).addClass('activeSlide');
$('.maskss').scrollTo($(this).attr('rel'), 500);
//solution below
$('.pagination li:nth-child(1) a').click();
return false;
});
更新:我找到了解决方案:$('.pagination li:nth-child(1) a').click();
I am using a jquery slider which automatically generates pagination bullets with the following html output:
<ul class="pagination">
<li class="current"><a href="#0">1</a></li>
<li><a href="#1">2</a></li>
<li><a href="#2">3</a></li>
<li><a href="#3">4</a></li>
</ul>
You can see an example of this at http://pixelcakecreative.com/
I want to be able to reset the slides position (set it back to the first slide) when you click on one of the following anchor links:
<li><a href="#" rel="#panel-1" class="activeSlide pita">Trendz<div class="buttonFade"></div></a></li>
<li><a href="#" class="pita" rel="#panel-2">Decibel<div class="buttonFade"></div></a></li>
<li><a href="#" class="pita" rel="#panel-3">UCC<div class="buttonFade"></div></a></li>
The slider is actually 3 sliders within a div that switches it's position based on whatever anchor (above code) is clicked. So basically, when you click on any of the links that switch the project slider, I want to go back to the first image of the slider.
I tried this with no luck, any idea on how to do this?
Ill start off the jquery with my existing code for clicking one of the trigger links:
$('#pixel-slider ul a.pita').click(function () {
$('#pixel-slider ul a').removeClass('activeSlide');
$(this).addClass('activeSlide');
$('.maskss').scrollTo($(this).attr('rel'), 500);
//solution below
$('.pagination li:nth-child(1) a').click();
return false;
});
UPDATE: I Found solution: $('.pagination li:nth-child(1) a').click();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的解决方案将起作用,但您可以简单地使用
first
选择器,而不是使用nth-child
并传递 1。li:first
将选择第一个.pagination
元素下的元素。Your solution will work but you can simply use the
first
selector instead of usingnth-child
and passing 1.li:first
will select the first element under.pagination
element.