如何写 - If Visible 选择器?
不知道如何写这个;
如果 .sub1 可见,则 .homepage fadeTo .25
Sub1 有淡入,如果 sub1 打开,我希望主页不透明度降至 0.25?
我有这个;
$("#cat").click(function(){
if ($('.sub1').is(':visible') ) {
$(".homepage").fadeTo(500, .25);}
else {
$(".homepage").fadeTo(500, 1);
}
我正在制作的实际网站> 网站样机 >单击类别在子菜单中淡出并使主页不透明度为25%,再次单击类别使子菜单淡出使主页100%......但是单击类别> >时尚>男士时尚>智能,调出“Mens Smart Fashion div”,但再次单击类别会使 Mens Smart 时尚 div 淡出,并带回 .sub1,但 .sub1 打开时 .homepage 为 100%,而不是 25%
Not sure how to write this;
If .sub1 is visible, .homepage fadeTo .25
Sub1 has a FadeIn and I want the homepage opacity to drop to .25 if the sub1 is open?
I have this;
$("#cat").click(function(){
if ($('.sub1').is(':visible') ) {
$(".homepage").fadeTo(500, .25);}
else {
$(".homepage").fadeTo(500, 1);
}
The actual website I am making > Website Mockup > Clicking Categories fades in the sub menu and makes homepage opacity 25%, clicking categories again, makes submenu fade Out making homepage 100%.....But clicking categories > Fashion > Mens Fashion > Smart, Brings up 'Mens Smart Fashion div" but clicking categories again fades the Mens Smart fashion div out, and brings .sub1 back, but the .homepage is 100% and not 25% when the .sub1 is open
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以过滤可见的
.sub1
并检查长度,如果有多个.sub1
,这可能不太好,也许可以为选择器添加一些特殊性。此技术将过滤掉第一个
.sub1
的 cssvisibility:hidden
或opacity: 0
元素 (':eq(0 )'
)。如果长度为 0,则条件将返回 false。修改:
我认为它不会淡入的原因是因为您的条件正在检查 opacicty:0,当淡入到 0.25 时您从未达到过。您应该设置条件来检查数字
.25
,以避免检查多个字符串,例如'.25'
或'0.25'
。 Firefox 报告'0.25'
。You can filter the visible
.sub1
and check the length, this may not be so great if there are multiple.sub1's
, maybe add a little specificity to the selector.This technique will filter out elements with css
visibility:hidden
oropacity: 0
for the first.sub1
(':eq(0)'
). If the length is 0 the condition will return false.Revised:
I think the reason the it would not fade back in is because your condition was checking for opacicty:0 which you never reached when fading to .25. You should set the condition to check a number
.25
to avoid checking multiple strings such as'.25'
or'0.25'
. Firefox reports'0.25'
.