简体   繁体   中英

How to animate font-size on mouseenter

I have issues animating the font-size on element mouseenter:

demo fiddle

HTML :

<p>Hello!</p>

Javascript :

$(document).ready(function () {
("p").mouseenter(function () {
    ("p").animate({
        "font-size": "50px"
    });
});

("p") should be $("p")
You're missing an });
and you're not using the jQuery library

$(document).ready(function () {
    $("p").mouseenter(function () {
        $(this).animate({"font-size": "50px"});
    });
});

Fiddle DEMO

A slightly nicer way to write the same would be:

jQuery(function($) {  // DOM ready shorthand

    $("p").mouseenter(function() {
        $(this).animate({ fontSize : 50 });
    });

});

Remember to always keep reference to the targeted Object Element $(this) to get the desired result.

you must use $ sign in your code try this code. i tested.

 $(document).ready(function () {
            $("p").mouseenter(function () {
                $(this).animate({
                    "font-size": "50px"
                });
            });
        });

You are missing the }); and $ signs, and the jQuery library in your fiddle.

http://jsfiddle.net/qjUc5/5/

$(document).ready(function(){
  $("p").click(function(){
    $(this).animate({fontSize:"30px"});
  });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM