我想使背景灰色当你点击搜索栏,但当你点击搜索栏,我想使CSS回来时,按钮点击每当你点击其他元素除了搜索栏。
$('input#srchInput').click(function(){
$("#dropNav .maxWidth").css({"filter":"brightness(48%) grayscale(12%)","background":"#d3d3d3c4"});
$("div#__nuxt").css({"filter":"brightness(48%) grayscale(12%)","background":"lightgrey"});
$("div#head").css("background","lightgrey");
$("#basket>.bskt").css({"color":"#1a1a1a","height":"40px"});
$("div#head").css("background","#1a1a1a85");
$("header #head").css("padding-bottom","25px");
$("#dropNav #nav-menu").css("margin-top","0px");
$("#uspAll").css("filter","brightness(48%) grayscale(12%)");
$("#basket").css("filter","brightness(48%) grayscale(12%)");
$("div#productBrowse").css("filter","brightness(48%) grayscale(12%)"); /* when it's not home */
});
let body = document.body;
body.addEventListener('click', function(e) {
if (e.target.id != 'srchInput')
{ $("#dropNav .maxWidth").css({"all":"initial"});
$("div#__nuxt").css({"all":"initial"});
$("div#head").css({"all":"initial"});
$("#basket>.bskt").css({"all":"initial"});
$("div#head").css({"all":"initial"});
$("header #head").css({"all":"initial"});
$("#dropNav #nav-menu").css({"all":"initial"});
$("#uspAll").css({"all":"initial"});
$("#basket").css({"all":"initial"});
$("div#productBrowse").css({"all":"initial"}); /* when it's not home }
});
});`
1条答案
按热度按时间hmmo2u0o1#
我已经为你写了一个codepen,示例,以便您可以了解如何才能实现它。
https://codepen.io/_makki/pen/zYmzKBp