検索の親に同じ z-index を与える
例が含まれていないため、htmlがどのように見えるかを知るのは難しいですが. 同じレベルに表示したい場合は、ゲートから同じ z-index を与えることができます。検索部分があるブロックがナビゲーションの後ろにある場合、それらは自然に同じ z-index で互いに重なり合います。
#nav,#search{position:absolute;z-index:9999}
たとえば、html の後にあると仮定すると、#search
上記のようになります。お気に入り:#nav
#search
#nav
<parent><nav/><search/></parent>
それがその前にあり、おそらく別の親にある場合は、次のようなものを使用できます。
#nav{z-index:9998} #search{z-index:9999}
htmlがより似ている場合は次のようになります。
<search/><parent><nav/></parent>
ただし、z-index をオン/オフする必要があり、 on でまったく修正できない#search
場合は、すでに正しい方向に向かっています。
このようなものはかなり簡単です:
$('#search input').on('focusin', function(){//on focus
$(this).siblings('.myIcon').css({zIndex: '9999'});
}).on('focusout', function(){//on un-focus
$(this).siblings('.myIcon').css({zIndex: '1'});
});
ただし、css を制御できた場合は、.myIcon
withのクラスを作成してz-index:9999
、代わりに次のようなものを使用できます。
.on{z-index:9999}/*added css*/
$('#search input').on('focusin focusout', function(){//on focus change
$(this).siblings('.myIcon').toggleClass('on');
});
フィドルを作った:http://jsfiddle.net/filever10/pxdz5/