Jquery - 将类添加到活动轮播图像的图像标签
我已经设法得到一个轮播,这样当图像更改时,它会显示您正在查看的图像编号。
如果选择的是图像编号 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)