需要js,TweenMax,IE8

时间:2014-01-18 13:29:12

标签: javascript requirejs tweenmax

我一直在努力让GreenSock JS(TweenMax)与require.js一起工作。我终于在现代浏览器中使用了它,但IE8却抛出了奇怪的错误。

我的主要要求配置文件:

require.config({

  baseUrl: '/ui/js',

  paths: {
    jquery: 'modules/libs/jquery-1.10.2',
    tweenmax: 'modules/vendor/greensock-js/TweenMax'
  },

  shim: {
    jquery: {
      deps: ['constants'],
      exports: 'jQuery'
    },
    tweenmax: {
      exports: 'TweenMax'
    }
  }

});

我的'模块'文件:

define([
  'jquery',
  'tweenmax'
], function($, TweenMax) {


  // Subscribe to the 'toggleFlyout' event
  // The event is used to open the flyout menu
  $(document).on('toggleFlyout', function() {
    var $html = $('html');
    var $page = $('.page');
    var openClass = 'js-flyout-open';

    if ( !$html.hasClass(openClass) ) {

      TweenMax.to($page, 0.2, {left:246, onStart: function() {
        $html.addClass(openClass);
      }});

    } else {

      TweenMax.to($page, 0.2, {left:0, onComplete: function() {
        $html.removeClass(openClass);
      }});

    }
  });



  // Publish the 'toggleFlyout' event
  // The event is published when the user click the menu button or the page overlay
  $(document).on('click', '.main-header__nav a, .toggle-flyout', function(event) {
    event.preventDefault(event);
    $(this).trigger('toggleFlyout');
  });


});

IE8引发了以下错误:

Expected identifier                        TweenMax.js, line 2295 character 4
'TweenMax' is null or not an object        flyout.js, line 38 character 4

请注意,代码在现代浏览器中运行良好。

1 个答案:

答案 0 :(得分:0)

TweenMax和Jquery是AMD模块,因为你不需要为它们提供shim配置的早期版本。 您还应该编译您的解决方案。 与模块加载器相比,Requirejs更适合作为依赖项管理器和打包器运行。 使用 https://github.com/gruntjs/grunt-contrib-requirejs 以供参考。