Jquery .load并调用其他脚本

时间:2014-10-10 12:39:02

标签: javascript jquery ajax load

我不是javascript和jquery的专家,这就是我发布可能是一个非常容易回答的问题的原因。我已经在网上搜索了一个解决方案但找不到任何我想要的东西。我正在做的是为我的整个网站使用ajax加载(使用popstate等),但我遇到的问题是在执行加载时重新加载其他各种脚本。下面是我存储在main.js文件中的加载技术的代码。我在这里只加载了一个高于加载技术的脚本,以免挤出这个问题中的代码。我也单独存储我的插件(tweenmax,jquery),我假设在加载执行时不会触发。我希望这个查询有意义,如果是这样,我真的很感激任何回复。欢呼声。

$(window).resize(function() {
   $('.gigDetail').css('width', $( window ).width() - $('.giglistingList').outerWidth() - $('.padSpace').outerWidth());
     // CENTERING 
   $.fn.CenterBoth = function() { this.css({ 'position' : 'absolute', 'top' : '50%', 'margin-top' : -(($(this).outerHeight()/2)), 'left' : '50%', 'margin-left' : -(($(this).outerWidth()/2)) }); return this; }
 //$(".giginfo").CenterBoth();
   $(".videoPlay").CenterBoth();
   $(".spotifyCounter").CenterBoth();
   $(".hometopLogo").CenterBoth();                    
}).resize();

// LOADING 
   $(function() {
       String.prototype.decodeHTML = function() {
       return $("<div>", {html: "" + this}).html();
   };
   var $main = $("main"),
//INITIALIZE 
   init = function() {
      $('main').removeClass('fadethisout');
      setTimeout(function () {
        $(".animEntry").each(function (i) {
             var self = this;
             var timer = i * 200;
       setTimeout(function () {
        $(self).addClass('animIn');
        }, timer);
       });
      }, 0);
  },

ajaxLoad = function(html) {
    document.title = html.match(/<title>(.*?)<\/title>/)[1].trim().decodeHTML();
         init();
 },
    loadPage = function(href) {$main.load(href + " main>*", ajaxLoad);};   
         init();
    $(window).on("popstate", function() {loadPage(location.href);});
    $(document).on("click", "nav.mainNav a, a.interior", function() {
    var href = $(this).attr("href");
       if ($('body').hasClass('show')) {
         setTimeout(function(){
            $('body').toggleClass('show');
          }, 0);  
     menuButton.classList.toggle('is-active');
    }
  setTimeout(function(){
       $('main').addClass('fadethisout');
  }, 350); 
  if (href.indexOf(document.domain) > -1
                 || href.indexOf(':') === -1)
    {
      setTimeout(function(){
          history.pushState({}, '', href);
          loadPage(href);
       }, 850);  
      return false;
     }
   });
}); // END OF LOADING FUNCTION

0 个答案:

没有答案