簡體   English   中英

jQuery何時動畫 <div> 失去重點

[英]jQuery animate when <div> loses focus

我的網站上有以下代碼:

<!-- Boat weather widget -->
<div id="boat_weather_tab_container">
    <div id="boat_weather_tab">
        <script type="text/javascript" src="widget.js"></script>
    </div>
    <div id="boat_weather_tab_button">
        <img src="images/blank150.gif">
    </div>
</div>

<script type="text/javascript">
$(document).ready(function(){
    $("#boat_weather_tab_button").click(function(){
        // boat_weather_tab_hidden = 1 on page load
        if (boat_weather_tab_hidden) {
            $("#boat_weather_tab").animate({
                marginTop: "-1px"
            }, 500);
            boat_weather_tab_hidden = 0;
        } else {
            $("#boat_weather_tab").animate({
                marginTop: "-254px"
            }, 500);
            boat_weather_tab_hidden = 1;
        }
    });
});
</script>

現在客戶想#boat_weather_tab滑回漲不只是當#boat_weather_tab_button被點擊,但是當用戶點擊其他地方的頁面,我的理解是,當父容器DIV相當於上#boat_weather_tab_container失去焦點。

我需要完成什么的jQuery?

也許

$(document).click(function(event)
{
 if(boat_weather_tab_hidden==0 && $("#boat_weather_tab").queue()==0 )
 {
   $("#boat_weather_tab").animate({
                marginTop: "-254px"
            }, 500);
            boat_weather_tab_hidden = 1;

 }
});

尚未測試,但想法是文檔單擊現在將僅在當前未設置動畫時隱藏船

您也許可以使用blur事件 從本質上講,這是失去焦點的行為。

$("#boat_weather_tab_container").blur(function() {
    //code to run on blur
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM