繁体   English   中英

WordPress:在div中加载动态页面内容后,加载JavaScript / JQuery

[英]WordPress: Load JavaScript / JQuery after dynamic page content loads in div

我正在尝试创建一个基于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

    });
});

});

运行滑块脚本时,它将滑块效果应用于现有元素。 如果将新内容放入页面中,则需要重新应用脚本。

在此行之后:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM