size style rule with CSS/javascript/jquery
I am using this code to dynamically resize text:
function fontResize(){
$('.features').css('font-size', ($(window).width()/100) + 'px');
}
fontResize();
$(window).resize( function () {fontResize()});
This works great for pulling the browser inwards but when i'm stretching the screen out on my 21" iMac, the text is too big for a set size DIV i have. how can i implement a solution whereby i can cap the maximum font size on the text. Will i be able to override this function above and put a max-font-size of 13px?
Thanks
function fontResize(){
var size = $(window).width()/100;
if ( size < 13 )
$('.features').css('font-size', size + 'px');
}
您可以实现一个sizeRange来定义最大和最小字体大小。
function fontResize(){
var sizeRange = [6, 13];
var size = $(window).width()/100;
if ( size <= sizeRange[1] && size >= sizeRange[0] ) {
$('.features').css('font-size', size + 'px');
} else {
// font-size out of range
}
}
链接地址: http://www.djcxy.com/p/15330.html
上一篇: CSS:100%的字体大小