Hover textbox remains fixed when selected

前端 未结 3 1687
清歌不尽
清歌不尽 2021-01-24 09:34

I\'ve created a search bar when, a user hover overs a button a textbox will appear. What i want to do is keep the text box to stay visible once the user has pressed the text box

3条回答
  •  无人共我
    2021-01-24 10:03

    Just add a check to see if the textbox has focus:

    $('#search-button, #search-text').hover(function searchbox () {
        $('#search-text').addClass("fixed-textbox");
    },function () {
        if(!$("#search-text").is(":focus")){
            $('#search-text').removeClass("fixed-textbox");
        }
    });
    
    //hide if focus out
    $("#search-text").on("focusout", function(){
        //Only if textbox does not have a value
        if($("#search-text").val() == null || $("#search-text").val() == ""){
            $('#search-text').removeClass("fixed-textbox");
        }
    });
    

提交回复
热议问题