如何获得当前“活动"的src?引导轮播中的图像 [英] how to get src of current "active" image inside bootstrap carousel

查看:61
本文介绍了如何获得当前“活动"的src?引导轮播中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次更改时,我都希望将活动图像的src拉到引导轮播中.下面是我现在可以用于第一个图像的内容,但是在下一个图像触发时不会更改.

I want to pull the src of the active image inside bootstrap carousel each time it changes. Below is what I have now which works for the first image, but doesn't change when the next one fires.

$(document).ready(function() {

    $('#galleryCarousel').on('slide.bs.carousel', function () {  
       var src = $('.active').find('img').attr('src');
       alert(src);
     });  
});

推荐答案

我遇到了同样的问题,这是我的方法.

I had the same issue, this is my approach.

由于幻灯片是动画事件,因此该类显然在与事件本身不同的时间触发射击.

Since the slide is an animation event, apparently the class toggle fire at a different time than the event itself.

$('#galleryCarousel').on('slide.bs.carousel', function () { 
  setTimeout(function(){
    var src = $('.active').find('img').attr('src'); alert(src);
  }, 300);
 });

我已经放了300个,但是您必须在轮播动画所用的时间上放在一起(默认情况下为180个,这可能取决于版本),放大一些会更安全.

I have put 300, but you have to put the same time you used for the carousel animation (180 by default, it may depend on the version) it would be safer to put a bigger number.

这篇关于如何获得当前“活动"的src?引导轮播中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆