Yepnope& Modernizr screen.width条件 [英] Yepnope & Modernizr screen.width Conditions
问题描述
我正在尝试(本地)使用Yiznope和Modernizr加载CSS& JS文件。所以我可以更好地管理文件,并轻松编码。
I am trying to (locally) use Yepnope with Modernizr to load CSS & JS Files. So I can manage the files better, and code easily.
这是当前的布局:
Modernizr.load([
{
test: Modernizr.mq('all and (max-width: 1070px)'),
yep: '/css/smartdevice.css','/js/smartdevice.js',
}
,
{
test: Modernizr.mq('all and (min-width: 481px) and (max-width: 1069px)'),
yep: '/css/tablet.css','/js/tablet.js',
},
{
test: Modernizr.mq('all and (max-width: 1070px)'),
yep: '/css/screen.css','/js/screen.js',
}
]);
我是JS的新手,但我可能会使用jQuery。但是它们都会立即加载,无论如何我可以根据px宽度加载CSS文件吗? (参考上述值)。我知道你可以做这个服务器端,但是在我的位置。
The I am fairly new to JS but I have used jQuery on may occasions. However they all load at once, is there anyway I can load the CSS files based on the px width? (ref above values). I am aware that you could do this server side, however in my position.
它必须是js中的本地端...我目前在SCSS中编码。一切都很好,这只是在窗口宽度上注入文件/显示文件的情况。
It has to be local side in js... I currently code in SCSS. Everything is fine that end, it is just a case of injecting the files/showing file on window width.
我认为我需要添加一个if语句,但任何将大大提供帮助!
I presume that I need to add an if statement, but any help would be greatly provided!
-Neil
PS我在本地运行,使用CodeKit在新的iMac上运行&安培; SCSS。
P.S I am running locally, on a new iMac using CodeKit & SCSS.
推荐答案
是的:'/ css / smartdevice.css','/ js / smartdevice。 js',
是非法的JS。如果您希望这是一个数组,请使用 yep:['/ css /smartdevice.css','/ js / smartdevice.js'],
。任何时候你在JavaScript对象中看到一个逗号,假装有一个换行符,你会看到这里出了什么问题:
yep: '/css/smartdevice.css','/js/smartdevice.js',
is illegal JS. If you want this to be an array, use yep: ['/css/smartdevice.css','/js/smartdevice.js'],
. Anytime you see a comma inside a JavaScript object, pretend there's a newline, and you'll see what's going wrong here:
Modernizr.load([
{
test: Modernizr.mq('all and (max-width: 1070px)'), // prop:val(=function)
yep: '/css/smartdevice.css', // prop:val(=string)
'/js/smartdevice.js', // ???
}
,...
这篇关于Yepnope& Modernizr screen.width条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!