MatchMedia.js 是否包含在 Modernizr JS 中?
我目前正在使用
<script src="https://raw.github.com/paulirish/matchMedia.js/master/matchMedia.js"></script>
<!-- <script>
</script>-->
<script>
if (matchMedia('only screen and (min-width : 1025px) and (max-width : 2048px)').matches) {
// smartphone/iphone... maybe run some small-screen related dom scripting?
$( document ).ready( function() {
var $body = $('body'); //Cache this for performance
var setBodyScale = function() {
var scaleFactor = 0.5,
scaleSource = $body.width(),
maxScale = 150,
minScale = 10;
var fontSize = scaleSource * scaleFactor; //Multiply the width of the body by the scaling factor:
if (fontSize > maxScale) fontSize = maxScale;
if (fontSize < minScale) fontSize = minScale; //Enforce the minimum and maximums
$('body').css('font-size', fontSize + '%');
}
$(window).resize(function(){
setBodyScale();
});
//Fire it when the page first loads:
setBodyScale();
});
}
</script>
Now,如果我将 matchmedia.js 替换为 Modernizr.JS 那么我上面的代码可以工作吗?
I'm currently using
<script src="https://raw.github.com/paulirish/matchMedia.js/master/matchMedia.js"></script>
<!-- <script>
</script>-->
<script>
if (matchMedia('only screen and (min-width : 1025px) and (max-width : 2048px)').matches) {
// smartphone/iphone... maybe run some small-screen related dom scripting?
$( document ).ready( function() {
var $body = $('body'); //Cache this for performance
var setBodyScale = function() {
var scaleFactor = 0.5,
scaleSource = $body.width(),
maxScale = 150,
minScale = 10;
var fontSize = scaleSource * scaleFactor; //Multiply the width of the body by the scaling factor:
if (fontSize > maxScale) fontSize = maxScale;
if (fontSize < minScale) fontSize = minScale; //Enforce the minimum and maximums
$('body').css('font-size', fontSize + '%');
}
$(window).resize(function(){
setBodyScale();
});
//Fire it when the page first loads:
setBodyScale();
});
}
</script>
Now if I replace matchmedia.js to Modernizr.JS then will my above code work ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Modernizr 使用类似的称为 mq 的东西。这是文档:http://www.modernizr.com/docs/#mq。
基本上,您可以将线路更改为:
Modernizr uses something similar called mq. Here's the documentation: http://www.modernizr.com/docs/#mq.
Basically, you'd change your line to: