jQuery return 值应在调整大小时更新

jQuery return value should be updated on resize

我有一个 jQuery 函数,它 returns 一个值。该值应该在调整大小时更新——但不幸的是它不是……

http://jsfiddle.net/9undwx90/

jQuery

var rem;

function myFunction() {
  var rem = $( 'html' ).css( 'font-size' );
  return rem;
}

$( document ).ready( function () {
    console.log( myFunction() );
});

$( window ).resize( function () {
    console.log( myFunction() );
});

CSS

html {
  font-size: 16px;
}

@media screen and (max-width: 1000px) {
  font-size: 14px;
}

@media screen and (max-width: 500px) {
  font-size: 12px;
}

您在 @media 块中的规则无效,因为它们缺少选择器。使用这个:

html {
    font-size: 16px;
}
@media screen and (max-width: 1000px) {
    html {
        font-size: 14px;
    }
}
@media screen and (max-width: 500px) {
    html {
        font-size: 12px;
    }
}

http://jsfiddle.net/koq1bh24/