如何避免jquery中mouseenter事件的闪烁?

我不知道确切的技术词汇,但是在关于’mouseenter’和’mouseleave’事件的jquery代码中,整个div会像按钮点击一样运动(闪烁?)而且我也使用’mouseover’和’mouseout’但同样的问题发生。

$total_doctors=mysql_fetch_array(mysql_query("select count(*) from doctor")); 

主要部分:

  

脚本代码:

 var docNumbr = ; $(document).ready(function(){ $({countNum: $('#countdoctor').text()}).animate({countNum: docNumbr}, { duration: 2000, easing:'linear', step: function() { $('#countdoctor').text(Math.floor(this.countNum)+1); } }); $('#countdoctor').mouseenter(function(){ $(this).text("Total Records: "+docNumbr).css({"opacity" : "0.5", "font-size" : "14px" }); }).mouseleave(function(){ $('#countdoctor').text(docNumbr).css({"opacity" : "1.0", "font-size" : "25px" }); }); }); 

我想避免在mouseenter和mouseleave上调整div的大小。 在此处输入图像描述在此处输入图像描述

正如您所注意到的那样,因为字体大小和文本会发生变化。 不一定只是使字体大小相同。 我认为当countdoctor具有静态高度和宽度时,你的问题将得到解决。 例如:

 #countdoctor { display:block; height:50px; /*Toggle just how you like it*/ width:100%; /*Depends on the parent, so just always take full width*/ }