开发者

Converting simple Javascript to jQuery

I have this:

<script type="text/javascript">
    window.onresize = fontResize;
    function fontResize() {
        document.body.style.fontSize = parseInt(document.documentElement.clientWidth/100) + 'px';
    }
</script>

Cou开发者_开发知识库ld someone have a crack at converting this to jQuery please, i have DIV's with class "features" and i need the P text to fill them when they are resized, so i need to font-size to grow/shrink along with the DIV. That make sense?

Thanks


Is this what you are looking for?

window.onresize = fontResize;
    function fontResize() {
    $('body').css('font-size',parseInt($('body').css('width'))/100) + 'px');

    }


Here... jQuerified

$(document).ready(function(){
    $(window).bind('resize initialSize',function(){
        $('body').css('font-size', ($(window).width()/8) + 'px');
    }).trigger('initialSize');
});


This one takes in account the initial size

function fontResize(){
   $('body').css('font-size', ($(window).width()/8) + 'px');
}

fontResize();
$(window).resize( fontResize );

http://jsfiddle.net/Hpgfp/1

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜