2014-01-18 43 views
0

我一直在搏鬥一下,讓GreenSock JS(TweenMax)與require.js一起工作。我終於在現代瀏覽器中工作了,但IE8拋出了奇怪的錯誤。要求js,TweenMax,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 

注意,該代碼是在現代瀏覽器中運行良好。

+0

TweenMax.js中的2295行是什麼? –

+0

它很奇怪。 2295行只是一個評論:\t \t \t // @私有飼料像camelCase屬性名稱,如「變換」,它會檢查它是否有效,或者是否需要供應商前綴。它返回更正的camelCase屬性名稱(即「WebkitTransform」或「MozTransform」或「transform」);如果沒有找到這樣的屬性,則返回null,如瀏覽器是IE8或之前的版本,則根本找不到「transform」 – tolborg

+0

你有沒有嘗試過使用Minify和最新版本的TweenMax(TweenMax.min.js)..它沒有在縮小版本中的評論,所以IE8不會拋出這個錯誤:) –

回答

0

TweenMax和Jquery是AMD模塊,因爲很早的版本你不需要填充配置。 你也應該編譯你的解決方案。 Requirejs比模塊加載器更適合作爲依賴管理器和打包器運行。 使用 https://github.com/gruntjs/grunt-contrib-requirejs 作爲參考。