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

javascript - jQuery: smooth animate font-size change on scroll - Stack Overflow

programmeradmin1浏览0评论

I have a jQuery animation function set-up to change the font size of the .header-wrap text when the document scrolls beyond 50px. This works, I'm not so keen on the solution I've got though, it's not very smooth, ideally I'd like the font-size to change smoothly as you scroll down the page, instead of having to stop scrolling the re-initiate the animation etc. It's just a bit jagged.
jsFiddle demo: /
HTML:

<div class="content-wrap"></div>
<div class="header-wrap">hello
    <br/>hello
    <br/>hello
    <br/>
</div>

jQuery:

$(document).scroll(function () {
    if (window.scrollY > 50) {
        $(".header-wrap").stop().animate({
            fontSize: '17px'
        });
    } else {
        $(".header-wrap").stop().animate({
            fontSize: '25px'
        });
    }
});

Any suggestions / better, smoother solutions to the one I've got are more than wele and greatly appreciated!

I have a jQuery animation function set-up to change the font size of the .header-wrap text when the document scrolls beyond 50px. This works, I'm not so keen on the solution I've got though, it's not very smooth, ideally I'd like the font-size to change smoothly as you scroll down the page, instead of having to stop scrolling the re-initiate the animation etc. It's just a bit jagged.
jsFiddle demo: http://jsfiddle/cXxDW/
HTML:

<div class="content-wrap"></div>
<div class="header-wrap">hello
    <br/>hello
    <br/>hello
    <br/>
</div>

jQuery:

$(document).scroll(function () {
    if (window.scrollY > 50) {
        $(".header-wrap").stop().animate({
            fontSize: '17px'
        });
    } else {
        $(".header-wrap").stop().animate({
            fontSize: '25px'
        });
    }
});

Any suggestions / better, smoother solutions to the one I've got are more than wele and greatly appreciated!

Share Improve this question asked Oct 29, 2013 at 15:59 user1374796user1374796 1,58213 gold badges46 silver badges76 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

You wont get a very smooth animation of fontSize. But if you only need patibility with modern browsers you could animate zoom instead.

You would have to fix your margins and positioning since those will be animated as well.

Here is a proof-of-concept fiddle.

发布评论

评论列表(0)

  1. 暂无评论