2010-03-11 56 views
0

,我需要適應,我有以下的jQuery:jQuery的幫助 - 出現下方,而不是上方

$(document).ready(function(){ 

$(".rss-popup a").hover(function() { 
$(this).next("em").stop(true, true).animate({opacity: "show", top: "-60"}, "slow"); 
}, function() { 
$(this).next("em").animate({opacity: "hide", top: "-70"}, "fast"); 
}); 

}); 

CSS:

.rss-popup { 
margin: 100px auto; 
padding: 0; 
width: 100px; 
position: relative; 
} 

div.rss-popup em { 
background: url(../images/rssbuttonbubble.png) no-repeat; 
width: 100px; 
height: 49px; 
position: absolute; 
top: -70px; 
left: -0px; 
text-align: center; 
text-indent: -9999px; 
z-index: 2; 
display: none; 
} 
#rss-icon { 
width: 42px; 
height: 42px; 
background: url(../images/rssbutton.png) no-repeat 0 0; 
text-indent: -9999px; 
margin: 0 auto; 
display: block; 
} 

的HTML:

<div class="rss-popup"> 
<a href="feed-link" id="rss-icon">RSS Feed</a> 
<em>Subscribe to our RSS Feed</em> 
</div> 

我想爲了讓rssbuttonbubble.png出現在下面,而不是從上面,可以提出任何建議,我怎麼能做到這一點?

回答

0

只需調整top值在動畫和CSS是你想要的距離:

$(".rss-popup a").hover(function() { 
$(this).next("em").stop(true, true).animate({opacity: "show", top: "60"}, "slow"); 
}, function() { 
$(this).next("em").animate({opacity: "hide", top: "70"}, "fast"); 
}); 

而且在CSS變化top: -70px;到:

top: 70px; 

這將使它顯示在下方,則如果你想要更高,就減少這些值,如果你想要更低,就增加。

0

尼克的回答是正確的。你會試圖通過CSS來做到這一點,但如果你不能通過Jquery實現類似的功能。有一個offset()函數返回匹配元素的屏幕位置。一旦你有了,你可以設置另一個元素的位置到這個位置,並將源元素的高度添加到Y座標。

請參閱jQuery documentation here.