Jquery - 将类添加到活动轮播图像的图像标签

发布于 2024-11-17 15:17:20 字数 1707 浏览 4 评论 0原文

我已经设法得到一个轮播,这样当图像更改时,它会显示您正在查看的图像编号。

如果选择的是图像编号 3,则列表向下 3 行是当前图像的代码。我是否能够自动将一个类添加到列表中嵌入的图像标签中?下面是我的代码,其中 itemvisiblein 函数基本上打印到某个 div。

我如何才能清除活动名称的所有类别,然后获取该编号并将该类别添加到该特定行的图像标签中? (与当前标题所在的类相同)(因此,如果选择了图像 3,则将“active”添加到该代码列表行下方嵌入的图像标签。

干杯,

<script type="text/javascript">
function itemVisibleIn(carousel, state){
    $("#gallerydescription").html(carousel.first);  //currently displays image number//

};

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
    easing: 'backout',
        animation: 1000,
    vertical: true,
        scroll: 1,
    itemVisibleInCallback: itemVisibleIn, 
       });
});

<ul id="mycarousel" class="jcarousel jcarousel-skin-tango">
        <li><a href="images/gallery/placeholder1.png" rel="shadowbox" title="This is the description"><img class="caption" src="images/gallery/placeholder1.png" width="750" height="450" title="test Title1" alt="This is the title" /></a></li>
        <li><a href="images/gallery/placeholder1.png" rel="shadowbox" title="This is the description"><img class="caption" src="images/gallery/placeholder1.png" width="750" height="450" title="test Title1" alt="This is the title" /></a></li>
        <li><a href="images/gallery/placeholder1.png" rel="shadowbox" title="This is the description"><img class="caption" src="images/gallery/placeholder1.png" width="750" height="450" title="test Title1" alt="This is the title" /></a></li>

所以简而言之

1)得到哪个线正用于该图像(列表线) 2) 清除所有以前的活动类别 3) 将活动类添加到当前所选图像的图像标签类(以及标题)

I have managed to get a carousel so that when the image is changed it will display what number image you are looking at.

if it is image number 3 that is chosen, 3 list rows down is the current images' code. Am i able to get this is automatically add a class to the image tag imbedded within the list? Below is my code with the itemvisiblein function basically printing out to a certain div.

How am i able clear all classes of the active name and then take that number and add the class to the image tag of that certain line? (same class as caption is currently in) (so if image 3 is selected then add "active" to the image tag imbedded within that code 3 list lines down.

Cheers,

<script type="text/javascript">
function itemVisibleIn(carousel, state){
    $("#gallerydescription").html(carousel.first);  //currently displays image number//

};

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
    easing: 'backout',
        animation: 1000,
    vertical: true,
        scroll: 1,
    itemVisibleInCallback: itemVisibleIn, 
       });
});

<ul id="mycarousel" class="jcarousel jcarousel-skin-tango">
        <li><a href="images/gallery/placeholder1.png" rel="shadowbox" title="This is the description"><img class="caption" src="images/gallery/placeholder1.png" width="750" height="450" title="test Title1" alt="This is the title" /></a></li>
        <li><a href="images/gallery/placeholder1.png" rel="shadowbox" title="This is the description"><img class="caption" src="images/gallery/placeholder1.png" width="750" height="450" title="test Title1" alt="This is the title" /></a></li>
        <li><a href="images/gallery/placeholder1.png" rel="shadowbox" title="This is the description"><img class="caption" src="images/gallery/placeholder1.png" width="750" height="450" title="test Title1" alt="This is the title" /></a></li>

So in short

1) get which line is being used for that image (list line)
2) clear all previous active classes
3) add class active to image tag class (along with caption) of the currently selected image

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

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

评论(1

ゝ偶尔ゞ 2024-11-24 15:17:20
$("img.caption").eq(index).addClass("extraClass");
$("img.caption").eq(index).addClass("extraClass");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文