2013-03-17 61 views

回答

1

將html更改爲此

<div id="footerSlideContainer"> 
    <div id="footerSlideButton"></div> 
    <div id="footerSlideContent"> 
     <div id="footerSlideText"> 
     <div id="footer_higher"> 
      <div id="footer_content"> 
       <div class="footbox"></div> 
        <div class="clear"></div> 
      </div> 
     </div> 
     </div> 
    </div> 
</div> 

現在按鈕位於容器內。現在您可以使用容器作爲$('#footerSlideContainer').hover()函數。該功能允許兩個參數,在鼠標上的一個函數和一個鼠標了,所以你jQuery的部分應該是這樣的:

jQuery(function($) { 
    $('#footerSlideContainer').hover(function() { 
      $('#footerSlideContent').animate({ height: '230px' }); 
      $(this).css('backgroundPosition', 'top left'); 
     }, 
     function() { 
      $('#footerSlideContent').animate({ height: '0px' }); 
      $(this).css('backgroundPosition', 'top left'); 
     } 
    );  
}); 

演示:jsFiddle

編輯 爲了保持顏色更改CSS爲:

#footerSlideContainer{position:fixed;top:50px;width:360px;left:0px} 
#footerSlideButton{background:red;position:fixed;top:0;left:0px;width:50px;height:50px} 
#footerSlideContainer:hover #footerSlideButton{background:green} 
#footerSlideContent{height:0;background:blue} 
+0

謝謝,在我原來的帖子中,我沒有提到,我想保持懸停狀態的顏色相同,當我滾動div。懸停的顏色是綠色的,所以我會怎麼做。我知道點擊功能,你添加一個toggleclass.clicked – 2013-03-17 22:15:45

+0

丹尼爾非常感謝工作!我插入了一個登錄表單框http://jsfiddle.net/MwChT/80/當您將鼠標懸停在下拉選擇框上時,您是否知道如何防止div關閉? – 2013-03-18 14:52:50

+0

在Safari看這個小提琴看起來很好,但在Firefox中它是一團糟。 – 2013-03-19 18:55:51

相關問題