2012-08-10 187 views
0

当鼠标悬停在使用jQuery的鼠标上时,如何缩放<h3>标记的文本?将鼠标悬停在鼠标上

这是JavaScript代码。

var bindBehaviors = function (scope) { 
      $('h3',scope).hover(
      function() { 
      $(this).css("font-size", "40px"); 
      }, 
      function() { 
      $(this).css("font-size", "25px"); 
      } 
      ); 
      } 
      bindBehaviors(this); 

它正在改变其大小,但是当我把鼠标放到其中包含<h3>文本行的任何地方它正在发生。为什么? 另一个问题是定位。

ASPX代码如下。

<form id="form1" runat="server"> 
    <div id="dictionary"> 
    </div> 
    <div class="letters"> 
    <div class="button" id="letter-a"> 
     <h3>A</h3> 
     <button type="button">Load</button> 
    </div> 
    <div class="button" id="letter-b"> 
     <h3>B</h3> 
     <button type="button">Load</button> 
    </div> 
    <div class="button" id="letter-c"> 
     <h3>C</h3> 
     <button type="button">Load</button> 
    </div> 
    <div class="button" id="letter-d"> 
     <h3>D</h3> 
     <button type="button">Load</button> 
    </div> 
    </div> 
    <div class="button" id="letter-f">F 
    <form> 
     <input type="text" name="term" value="" id="term" /> 
     <input type="submit" name="search" value="search" id="search" /> 
    </form> 
    </div> 
    <div id="loading"> 
    Loading... 
    </div> 
</form> 
+0

只需增加字体。这可以用css'h3:hover {font-size:50px; }' – elclanrs 2012-08-10 07:34:55

+2

试试这个插件http://janne.aukia.com/zoomooz/ – undefined 2012-08-10 07:35:23

回答

1

HTML:<h3>Some text</h3>

CSS:h3 {font-size: 14px;}

的jQuery:

$('h3').hover(
    function() { 
    $(this).css("font-size", "16px"); 
    }, 
    function() { 
    $(this).css("font-size", "14px"); 
    } 
); 
+0

它正在工作,但是当鼠标悬停在文本所在行的任何位置时,文本的字体会发生变化。我不需要它。当我放置/悬停鼠标时更改大小。 – user1544975 2012-08-10 07:40:30

+0

当我从中删除鼠标时,它不会调整到原始大小。 – user1544975 2012-08-10 07:44:46

+0

对不起,有一个错字。现在它应该调整到原始大小。至于其他问题 - 你可以发布你的代码吗? – 2012-08-10 07:47:19

2

你有几个选项。

只是css。

h3 
{ 
    transform: scale(1); 
} 

h3:hover 
{ 
    transform: scale(1.5); 
} 

JS(jQuery的)

$('h3').hover(
    function() 
    { 
     $(this).effect('scale',{percent:200},1000); 
    }, 
    function() 
    { 
     $(this).effect('scale',{percent:50},1000); 
    },  
); 

喜欢的东西可能会有帮助。