【问题标题】:Loading Flexslider dynamically via AJAX通过 AJAX 动态加载 Flexslider
【发布时间】:2015-02-10 02:05:22
【问题描述】:

我有一个带有菜单的页面 index.html,该菜单通过 AJAX 将页面 1.html、2.html、3.html 等中的内容动态加载到 index.html 中的 DIV 中。

1.html中的内容内置了一个Flexslider,通过AJAX加载后不会被初始化。如果我直接调用/刷新页面,滑块会完美加载!

我通过

调用 index.html 中的滑块
<script type="text/javascript" charset="utf-8">
  $(window).load(function() {
  $('.flexslider').flexslider({
     animation: "slide",
    manualControls: ".flex-control-nav li"
    });
 });
</script>    

我的 AJAX 调用在外部 .js 中,看起来像这样

$(document).ready(function() {

var hash = window.location.hash.substr(1);
var href = $('#nav2mobile li a').each(function(){
    var href = $(this).attr('href');
    if(hash==href.substr(0,href.length-5)){
        var toLoad = hash+'.html #content2';
        $('#content2').load(toLoad)
    }                                           
});

$('#nav2mobile li a').click(function(){

    var toLoad = $(this).attr('href')+' #content2';
    $('#content2').hide('normal',loadContent);
    $('#load').remove();
    $('#load').fadeIn('slow');
    window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
    function loadContent() {
        $('#content2').load(toLoad,'',showNewContent())
    }
    function showNewContent() {
        $('#content2').show('normal',hideLoader());
    }
    function hideLoader() {
        $('#load').fadeOut('normal');
    }
    return false;

});

});

滑块加载到 index.html 后,我不知道如何启动它

我尝试将 Slider 调用放入 .click(funktion(),但这也不起作用..

任何人的想法?

谢谢,感谢任何帮助!

【问题讨论】:

    标签: jquery ajax dynamic load flexslider


    【解决方案1】:

    您是否尝试将$(window).load(function() 更改为$(document).ready(function ()

    window.onload vs $(document).ready()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-12
      • 2013-05-08
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      相关资源
      最近更新 更多