【问题标题】:WordPress: Load JavaScript / JQuery after dynamic page content loads in divWordPress:在 div 中加载动态页面内容后加载 JavaScript / JQuery
【发布时间】:2014-06-03 18:15:57
【问题描述】:

我正在尝试创建一个基于 WordPress 的单页网站,并将页面内容加载到 div onClick 中。但是,由于在加载页面内容之前已经加载了 JavaScript,因此脚本不起作用。

临时站点在这里:http://upsilon.lunariffic.com/~swstr0/

如果您点击客户-->我们与谁合作,您会看到问题。不会滑动的徽标滑块。没有箭头,并且根据浏览器的不同,链接不起作用。

可能是因为这个脚本已经加载了? http://upsilon.lunariffic.com/~swstr0/wp-content/plugins/logo-slider/jquery.cycle.all.min.js?ver=3.9.1

这是我目前用来让 div 向下(或向上)滑动并加载页面内容的代码:

<script type="text/javascript">
jQuery(function($) {
$("li.btn-slide a").on('click', function(e){
    e.preventDefault();

    var post_url = $(this).attr("href");
    var post_id  = $(this).attr("rel");

    $("#page-con").html("loading...")
                  .load(post_url, function() { // content loaded callback

        var pageconHeight = $("#page-con").height();  // Find the height of the content inside #panel
         $("#panel").animate({height: pageconHeight}, "slow"); // Animate the height of #panel

    });
});

});

【问题讨论】:

    标签: javascript jquery wordpress onclick cycle


    【解决方案1】:

    当您运行滑块脚本时,它会将滑块效果应用于现有元素。如果您在页面中添加新内容,则需要重新应用脚本。

    在这一行之后:

    $("#panel").animate({height: pageconHeight}, "slow"); // Animate the height of #panel
    

    添加

    $('#idOfYourLoadedContent').cycle();
    

    【讨论】:

    • 好吧,我猜在我的实例中#idOfYourLoadedContent 将是#page-con。我试过了,但我得到的只是控制台中的错误,如下所示:[cycle] terminating;选择器找到的零个元素
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-09
    • 1970-01-01
    • 2013-12-30
    • 2012-08-24
    • 1970-01-01
    • 2016-03-13
    • 2014-02-23
    相关资源
    最近更新 更多