English 中文(简体)
前后菜单选项卡Jquery
原标题:Receding and Protruding menu tabs Jquery
  • 时间:2011-02-15 09:28:09
  •  标签:
  • jquery

Sorry if this is a silly question but I have been on web design for 2 weeks and I am trying to make some menu tabs. Specificity ones that protrude when you mouseover and recede back to start position when mouseleave. I have made some code but it seems to act strangely. When I mouse over its fine and the tab comes down 10px but when I leave the second time on any tab it recedes 10px then another 10px and it adds up each time incrementally, 20, 30, 40 etc.

我试过突然停下来,但我仍在学习。如果它很乱,请告诉我。

这是代码。

$(document).ready(function(){
 $( .buttons ).mouseover(function(){
  $(this).animate({top:  +=10 }, 200, function() {
   $(this).mouseleave(function(){
    $(this).animate({top:  +=-10 }, 200, function() {

    });
   });
  });
 });
});
最佳回答

看看http://jsfiddle.net/thewebdes/DqfJ5/

这就是你想要的吗?

HTML格式

<ul>
    <li><a href="#" class="buttons">Link 1</a></li>
    <li><a href="#" class="buttons">Link 2</a></li>
    <li><a href="#" class="buttons">Link 3</a></li>
</ul>

CSS格式

body { font-family: arial, helvetica, sans-serif; }
li { float: left; display: inline; margin: 0 1px 0 0; }
a:link, a:visited { position: relative; display: block; padding: 5px 10px; text-decoration: none; color: #39F; background: #039; border: 1px solid #03C; }
a:hover, a:active { color: #F90; background: #960; border: 1px solid #630; }

JS公司

$( .buttons ).hover(function() {
    $(this).stop(true,true).animate({top:  -=10 , paddingBottom:  15px }, 200);
}, function() {
    $(this).stop(true,true).animate({top:  +=10 , paddingBottom:  5px }, 200);
});

--编辑以回答评论--

如果不希望文本移动:

$( .buttons ).hover(function() {
    $(this).stop(true,true).animate({paddingBottom:  15px }, 200);
}, function() {
    $(this).stop(true,true).animate({paddingBottom:  5px }, 200);
});

如果您这样做:

$( .buttons ).hover(function() {
    $(this).stop(true,true).animate({paddingTop:  15px }, 200);
}, function() {
    $(this).stop(true,true).animate({paddingTop:  5px }, 200);
});
问题回答

暂无回答




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签