2016-11-10 27 views
0

我想添加类,然后触发一个事件,但不幸的是它不工作,我想我尝试了错误的方式,有人可以建议吗?以下是我的代码添加类,然后触发一个事件JQuery

首先我要补充类

$(".hospital_listing_front").addClass('flexslider-hospital'); 

一旦类加那么火了以下功能(这是关系到flexslider,将增加flexslider功能)

$(".flexslider-hospital").flexslider({ 
    animation: "slide", 
    animationLoop: false, 
    itemWidth: 210, 
    itemMargin: 48, 
    pausePlay: false 
    }); 

添加班级正在工作,但flexslider不工作

请建议如何处理此问题。

在此先感谢

+2

这是什么问题? – Satpal

+0

添加班级正在工作,但flexslider不工作 –

+1

可能有一些其他问题,您未在代码中显示发布完整代码 – Bharat

回答

1

我认为它可能有提供一些时间来添加类。如可能会使用setTimeout将解决您的问题只是尝试让我知道,如果你再次面对同样的问题。

$(".hospital_listing_front").addClass('flexslider-hospital'); 

setTimeout(function() { 
    $(".flexslider-hospital").flexslider({ 
    animation: "slide", 
    animationLoop: false, 
    itemWidth: 210, 
    itemMargin: 48, 
    pausePlay: false 
    }); 
}, 1000); 
+0

令人惊叹的是,它在setTimeout中添加时很有效,非常感谢! –

0

为什么不链接它?

$(".hospital_listing_front").addClass('flexslider-hospital').flexslider({ 
    animation: "slide", 
    animationLoop: false, 
    itemWidth: 210, 
    itemMargin: 48, 
    pausePlay: false 
    }); 

,或者如果你想加强它:

$hospital = $(".hospital_listing_front"); 
$hospital.addClass('flexslider-hospital') 
$hospital.flexslider({ 
    animation: "slide", 
    animationLoop: false, 
    itemWidth: 210, 
    itemMargin: 48, 
    pausePlay: false 
    }); 

但如果Flex滑块简化版,工作,有可能是一个问题与您的HTML格式化。 没有你的html,很难说肯定..

+0

感谢您的答案,我也认为链接会解决我的问题,但不幸的是,我不得不与按照@SudharsanS建议的Settimeout选项 –

相关问题