简体   繁体   English

如何在mouseenter上设置字体大小的动画

[英]How to animate font-size on mouseenter

I have issues animating the font-size on element mouseenter: 我在元素mouseenter上设置字体大小动画时遇到问题:

demo fiddle 演示小提琴

HTML : HTML

<p>Hello!</p>

Javascript : Javascript

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

("p") should be $("p") ("p")应该是$("p")
You're missing an }); 您缺少});
and you're not using the jQuery library 而且您没有使用jQuery库

$(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. 请记住,始终保持引用目标对象元素$(this)以获取所需的结果。

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. 和$符号,以及您的小提琴中的jQuery库。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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