最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is MatchMedia.js included in Modernizr JS? - Stack Overflow

programmeradmin3浏览0评论

I'm currently using

<script src=".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 ?

I'm currently using

<script src="https://raw.github./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 ?

Share Improve this question edited Dec 22, 2011 at 9:55 Jitendra Vyas asked Dec 22, 2011 at 9:40 Jitendra VyasJitendra Vyas 153k240 gold badges587 silver badges868 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

Modernizr uses something similar called mq. Here's the documentation: http://www.modernizr./docs/#mq.

Basically, you'd change your line to:

if (Modernizr.mq('only screen and (min-width : 1025px) and (max-width : 2048px)')) {
发布评论

评论列表(0)

  1. 暂无评论