local-host 2012-12-15 11:40 采纳率: 100%
浏览 58

通过Ajax加载Flexslider

I'm using the jQuery plugin easytabs to load HTML from another page. The HTML may consist of a jQuery flexslider, but the slider doesn't work after it has been loaded since the JavaScript already has been run. Here's my code:

<ul class="portfolio-thumbnails">
    <li><a href="portfolio.html #item1" data-target="#item1">Load via ajax</a></li>
</ul>

<div class="panel-container">
    <div id="item1" class="portfolio-item"></div> /* The slider loaded from the ajax call will be appended to this div */
</div>

I have tried calling the flexslider when I click on the Load via ajax link, like so:

$(".portfolio-thumbnails li a").click(function () { 
    $('.flexslider').flexslider({
        animation: "slide"
    });
});

...but that only works the second time when I click. I guess the flexslider script is being called before it has loaded the HTML via ajax. I have also tried calling the flexslider script from the external page (portfolio.html), but that doesn't work.

Any ideas?

  • 写回答

1条回答 默认 最新

  • 游.程 2012-12-15 11:51
    关注

    Could you put it in your success callback of your easy tab ajax request? Append the following to your easytab event:

      .bind('easytabs:ajax:complete', function() {
        $('.flexslider').flexslider({
            animation: "slide"
        });
      });
    

    Found under event-hooks in the documentation:

    RESPONSE TO NOT LOADING AFTER TAB CLICK

    enter image description here

    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配