0
我main.js文件看起來像這樣:RequireJS:執行jQuery代碼domready中
require.config({
paths: {
"jquery": "3rd_party/jquery-2.0.3.min",
"bootstrap": "3rd_party/bootstrap.min",
"handlebars":"3rd_party/handlebars",
"html5shiv":"3rd_party/html5shiv",
"modernizr":"3rd_party/modernizr",
"respond":"3rd_party/respond.min",
"jquery-ui":"3rd_party/jquery-ui-1.10.3.custom.min",
'fancybox':'3rd_party/jquery.fancybox.pack'
},
shim: {
"bootstrap": {
deps: ["jquery"]
},
"jquery-ui": {
deps: ["jquery"]
},
"fancybox": {
deps: ["jquery"]
}
}
})
requirejs(["jquery", "fancybox","controllers/" + controller,'modules/login','bootstrap','handlebars','html5shiv','modernizr','respond', 'jquery-ui'],function($,fancybox,controller,handleLogin) {
$(document).ready(function() {
if ($(window).width()>991) {
$(".sidebar").height($(".maincontent").height());
}
$(".searchresults .greencol").height($(".searchresults .article").first().height()-100);
$('.login').click(function() {
handleLogin();
return false;
})
$('.fancybox-inline').fancybox({
maxWidth : 800,
maxHeight : 600
});
$('.fancybox-document').fancybox({
width: 660,
height: 440
});
$('.fancybox-close-button').click(function() {
$.fancybox.close();
return false;
})
});
controller.init();
})
一切發生
現在,它其實需要一些時間來執行該位:
if ($(window).width()>991) {
$(".sidebar").height($(".maincontent").height());
}
而且該頁面會產生一點閃爍。 我唯一的想法是將jQuery單獨包含在index.html中,並將其放在<script>
標記中。但後來我的RequireJS設置打破了。
你有什麼建議如何做到這一點?
感謝您的建議,完美的作品。我總是堅持「1要求每個文件」規則,並沒有意識到我可以有更多的:) –
我很高興它的工作!加註答案並將其標記爲「已接受」是有意義的。 – Louis
標記爲已接受,但我沒有足夠的信譽upvote,對不起 –