将 jquery 属性应用到另一个 div

发布于 2024-12-01 18:19:54 字数 1503 浏览 0 评论 0原文

我正在使用 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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

好听的两个字的网名 2024-12-08 18:19:54

您的解决方案将起作用,但您可以简单地使用 first 选择器,而不是使用 nth-child 并传递 1。li:first 将选择第一个.pagination 元素下的元素。

 $('.pagination li:first a').click();

Your solution will work but you can simply use the first selector instead of using nth-child and passing 1. li:first will select the first element under .pagination element.

 $('.pagination li:first a').click();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文