2012-05-18 270 views
0

我正在爲客戶端的網站設置一個啓動頁面。jQuery div寬度動畫不會流暢動畫

這個想法是,藍條會在懸停的文字上生長,文字會改變顏色。我有基本的元素,但由於某些原因,酒吧的表現非常糟糕,不會保持原樣。這似乎是浮動的結果,但我看不到如何讓寬度向左增長。

這裏是我的jQuery代碼

$(document).ready(function(e) { 
$('.work_link').hover(
function() { 
    $('.work_link').stop(true,false).animate({color:'#ffffff'}, 500); 
     $('#splash_bar_mono').stop(true, false).animate({width:'350px'}, 500).css({'float':'right'}); 
     //mouseover 
}, 
function() { 
$('.work_link').stop(true, false).animate({color:'#000'}, 500); 
$('#splash_bar_mono').stop(true, false).animate({width:'10px'}, 500);//mouseout 
}); 
$('.play_link').hover(
function() { 
    $('.play_link').stop(true, false).animate({color:'#ffffff'}, 500); 
    $('#splash_bar_mono').animate({width:'325px'}, 500).css({'float':'left'});//mouseover 
}, 
function() { 
    $('.play_link').stop(true, false).animate({color:'#000'}, 500);//mouseout 
    $('#splash_bar_mono').stop(true, false).animate({width:'10px'}, 500); 
}); 
}); 

下面是網站的HTML

<body id="splash"> 
<div id="splash_center"> 
     <div style="z-index:200;" id="splash_work"><a style="z-index:200;" class="work_link" href="#">WORK</a></div> 
     <div style="z-index:200;"id="splash_play"><a style="z-index:200;" class="play_link" href="#">PLAY</a></div> 
    <div id="splash_bars"> 
     <div style="z-index:-200;" id="splash_bar_mono"></div>   
    </div> 

</div> 
    <div id="splash_graphic"></div> 


</body>  
</html> 

http://fefifofilms.com/

回答

1

爲什麼你的問題的主要原因是使用其他的div下方滑動的。這導致您的懸停方法在幻燈片下方切換。

我已經能夠使用稍微不同的方法解決這個問題。而不是使用背景顏色爲不同的欄設置動畫。我選擇在splash_work和splash_play上使用背景漸變。

這是jsFiddle的一個例子。你

http://jsfiddle.net/9H4JU/

還可以下載我從http://sexyselect.net/blog/image.axd?picture=2012%2f5%2fgrad.png

如何這有助於使用的漸變...

+0

哇,這是順暢了很多。我認爲這是一個更好,更簡單的解決方案。我不知道你可以如此動畫化背景位置。天才。 – ScottyC

+0

這很好,但它在Firefox中被破壞了......我認爲它與firefox不支持background-position-x功能有關。有什麼想法嗎? – ScottyC