我的main.js文件如下所示:
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设置中断了。
你对如何做到这一点有什么建议吗?
发布于 2013-11-14 17:43:43
所以你希望大小调整尽早发生。我还不完全清楚您是如何在前面尝试这样做的,但是这样做才能使它尽早发生,而不是破坏或绕过RequireJS:
requirejs回调中删除以下内容:
如果($(窗口).width()>991){.width}requirejs的调用:
_(_顺便说一句,这不需要在不同的<script>元素中。您可以将新的requirejs电话放在您已经拥有的电话前面。这样做,一旦加载了jQuery,就会进行调整大小。
https://stackoverflow.com/questions/19980026
复制相似问题