[英]Using a variable in enquire.js register method
I am trying to using a variable in the register method of enquire.js. 我正在尝试在enquire.js的register方法中使用变量。 I'm going to be reusing enquire in a few different places in my javascript file, so I would like to be able to manage the widths it is using easier.
我将在javascript文件中的几个不同位置重复使用查询,因此我希望能够更轻松地管理宽度。
This is the basic call 这是基本电话
enquire.register("screen and (max-width:860px)", {
});
This is sort of what I was hoping I could do but it's not working. 这是我希望可以做的事情,但是没有用。
var $small = '600px';
enquire.register("screen and (max-width:'$small')", {
});
Ah. 啊。 Me being stupid and forgetting how concatenating works.
我很愚蠢,忘记了串联的工作原理。 I needed to end the string with the same type of quotes and then use the plus symbol to concatenate the variable.
我需要使用相同类型的引号将字符串结尾,然后使用加号将变量连接起来。 I then used the same quotes again to finish open and close the remainder of the string.
然后,我再次使用相同的引号完成打开和关闭字符串的其余部分。
var $small = '600px';
enquire.register("screen and (max-width:" + $small + ")", {
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.