2012-08-10 186 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); 
    },  
); 

喜歡的東西可能會有幫助。