0

マウスが要素に入ると要素のフォントサイズを変更し、マウスが要素を離れると元のフォントサイズに戻す関数を作成しようとしています。これは私が持っているものです:

   $(".month").hover(function(){

        var size = $(this).css("font-size");

        $(this).stop().animate({
            fontSize: start_font + font_off,
            opacity: '1'
        }, 200);    

    },function(){

        $(this).stop().animate({
            fontSize: size,
            opacity: '1'
        }, 200);
    });

マウスを離すとフォントサイズが変更されますが、マウスが離れても同じサイズのままです。(フォントサイズの変更後にアラート(サイズ)を実行しましたが、正しい値が保持されています。)ここで何が間違っていますか?

4

5 に答える 5

6

これは、CSS を使用して簡単に実現できます。

.month:hover {
  font-size: 150%;
  }

ただし、jquery では次のことができます。

$(".month").hover(function(){
  $(this).
    stop().
    animate({
      fontSize: "5em"
      }, 1000);
  },
  function(){
    $(this).
      stop().
      animate({
        fontSize: "1em"
        }, 1000);
    }
  );

jsfiddle を参照してください。注、私はソースems以来使用していますThe “em” is a scalable unit that is used in web document media. An em is equal to the current font-size, for instance, if the font-size of the document is 12pt, 1em is equal to 12pt.

于 2013-05-27T06:02:14.273 に答える
2

私が理解しているように、これはあなたを助けるでしょう

$(".month").hover(function(){

    var size = $(this).css("font-size");

    $(this).stop().animate({
        fontSize: start_font + font_off,
        opacity: '1'
    }, 200);    

},function(){
    var size = $(this).css("font-size");      //Add this
    $(this).stop().animate({
        fontSize: size - font_off,   
        opacity: '1'
    }, 200);
});

または、css を介して :hover like で行うことができます

.month:hover {
   font-size: 150%;
}
于 2013-05-27T06:02:08.190 に答える