gpt4 book ai didi

javascript - 根据另一个元素的数据属性隐藏一个元素

转载 作者:可可西里 更新时间:2023-11-01 13:24:19 24 4
gpt4 key购买 nike

我想使用 CSS/JavaScript 隐藏基于另一个数据元素的元素。类和数据元素是使用我不想弄乱的标准 javascript 片段控制的。

<span role="img" data-slide="3" aria-label="Item 3 of 5 displayed" class="sapMCrslActive">3</span>

所以当上面的 span 包含 data-slide="3" 并且包含 class="sapMCrslActive" 时。

我想调用这个:

.sapMCrslHud .sapMCrslNext {
visibility: hidden;
}

隐藏这个元素:

<a class="sapMCrslNext" href="#" data-slide="next" tabindex="-1">
<div class="sapMCrslArrowInner"><span id="__carousel0-arrowScrollRight" data-sap-ui="__carousel0-arrowScrollRight" role="presentation" aria-hidden="true" data-sap-ui-icon-content="" class="sapUiIcon sapUiIconMirrorInRTL" style="font-family:'SAP-icons'"></span>
</div></a>

完整的 HTML 元素:

    <div id="__carousel0" data-sap-ui="__carousel0" data-sap-ui-fastnavgroup="true" data-sap-ui-customfastnavgroup="true" style="width:100%;height:100%" class="sapMCrsl sapMCrslFluid sapUiContentPadding" tabindex="0" role="list" aria-activedescendant="__carousel0-__box25-slide">
<div class="sapMCrslInner sapMCrslBottomOffset" style="transform: translate3d(-1280px, 0px, 0px);">
<div class="sapMCrslItem sapMCrslActive" id="__carousel0-__box21-slide" role="listitem" aria-posinset="1" aria-setsize="5">
<div id="__container1" data-sap-ui="__container1" style="width: 100%; height: 100%; overflow: hidden;" class="sapMScrollCont">
<div id="__container1-scroll" class="sapMScrollContScroll">
<div class="sapMCrslItemTable" data-sap-ui-preserve="__html0" id="__html0">
<div class="sapMCrslItemTableCell">
<div id="__box21" data-sap-ui="__box21" class="bgColor sapMFlexBox sapMFlexBoxAlignContentStretch sapMFlexBoxAlignItemsCenter sapMFlexBoxBGTransparent sapMFlexBoxJustifyStart sapMFlexBoxWrapNoWrap sapMVBox"></div>
</div>
</div>
</div>
</div>
</div>
<div class="sapMCrslItem sapMCrslActive" id="__carousel0-__box22-slide" role="listitem" aria-posinset="2" aria-setsize="5">
<div id="__container2" data-sap-ui="__container2" style="width: 100%; height: 100%; overflow: hidden;" class="sapMScrollCont">
<div id="__container2-scroll" class="sapMScrollContScroll">
<div class="sapMCrslItemTable" data-sap-ui-preserve="__html1" id="__html1">
<div class="sapMCrslItemTableCell">
<div id="__box22" data-sap-ui="__box22" class="bgColor sapMFlexBox sapMFlexBoxAlignContentStretch sapMFlexBoxAlignItemsCenter sapMFlexBoxBGTransparent sapMFlexBoxJustifyStart sapMFlexBoxWrapNoWrap sapMVBox"></div>
</div>
</div>
</div>
</div>
</div>
<div class="sapMCrslItem sapMCrslActive" id="__carousel0-__box23-slide" role="listitem" aria-posinset="3" aria-setsize="5">
<div id="__container3" data-sap-ui="__container3" style="width: 100%; height: 100%; overflow: hidden;" class="sapMScrollCont">
<div id="__container3-scroll" class="sapMScrollContScroll">
<div class="sapMCrslItemTable" data-sap-ui-preserve="__html2" id="__html2">
<div class="sapMCrslItemTableCell">
<div id="__box23" data-sap-ui="__box23" class="bgColor sapMFlexBox sapMFlexBoxAlignContentStretch sapMFlexBoxAlignItemsCenter sapMFlexBoxBGTransparent sapMFlexBoxJustifyStart sapMFlexBoxWrapNoWrap sapMVBox"></div>
</div>
</div>
</div>
</div>
</div>
<div class="sapMCrslItem sapMCrslActive" id="__carousel0-__box24-slide" role="listitem" aria-posinset="4" aria-setsize="5">
<div id="__container4" data-sap-ui="__container4" style="width: 100%; height: 100%; overflow: hidden;" class="sapMScrollCont">
<div id="__container4-scroll" class="sapMScrollContScroll">
<div class="sapMCrslItemTable" data-sap-ui-preserve="__html3" id="__html3">
<div class="sapMCrslItemTableCell">
<div id="__box24" data-sap-ui="__box24" class="bgColor sapMFlexBox sapMFlexBoxAlignContentStretch sapMFlexBoxAlignItemsCenter sapMFlexBoxBGTransparent sapMFlexBoxJustifyStart sapMFlexBoxWrapNoWrap sapMVBox"></div>
</div>
</div>
</div>
</div>
</div>
<div class="sapMCrslItem sapMCrslActive" id="__carousel0-__box25-slide" role="listitem" aria-posinset="5" aria-setsize="5">
<div id="__container5" data-sap-ui="__container5" style="width: 100%; height: 100%; overflow: hidden;" class="sapMScrollCont">
<div id="__container5-scroll" class="sapMScrollContScroll">
<div class="sapMCrslItemTable" data-sap-ui-preserve="__html4" id="__html4">
<div class="sapMCrslItemTableCell">
<div id="__box25" data-sap-ui="__box25" class="bgColor sapMFlexBox sapMFlexBoxAlignContentStretch sapMFlexBoxAlignItemsCenter sapMFlexBoxBGTransparent sapMFlexBoxJustifyStart sapMFlexBoxWrapNoWrap sapMVBox"></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="__carousel0-hud" class="sapMCrslHud sapMCrslHudBottom sapMCrslRightmost">
<a class="sapMCrslPrev" href="#" data-slide="prev" tabindex="-1">
<div class="sapMCrslArrowInner"><span id="__carousel0-arrowScrollLeft" data-sap-ui="__carousel0-arrowScrollLeft" role="presentation" aria-hidden="true" data-sap-ui-icon-content="" class="sapUiIcon sapUiIconMirrorInRTL" style="font-family:'SAP-icons'"></span>
</div>
</a>
<a class="sapMCrslNext" href="#" data-slide="next" tabindex="-1">
<div class="sapMCrslArrowInner"><span id="__carousel0-arrowScrollRight" data-sap-ui="__carousel0-arrowScrollRight" role="presentation" aria-hidden="true" data-sap-ui-icon-content="" class="sapUiIcon sapUiIconMirrorInRTL" style="font-family:'SAP-icons'"></span>
</div>
</a>
</div>
<div class="sapMCrslControlsNoArrows sapMCrslControlsBottom">
<div id="__carousel0-pageIndicator" style="" class="sapMCrslBulleted"> <span role="img" data-slide="1" aria-label="Item 1 of 5 displayed" class="">1</span>
<span role="img" data-slide="2" aria-label="Item 2 of 5 displayed" class="">2</span>
<span role="img" data-slide="3" aria-label="Item 3 of 5 displayed" class="">3</span>
<span role="img" data-slide="4" aria-label="Item 4 of 5 displayed" class="">4</span>
<span role="img" data-slide="5" aria-label="Item 5 of 5 displayed" class="sapMCrslActive">5</span>
</div>
</div>
</div>

最佳答案

您必须使用一个时间间隔来定期检查幻灯片是否处于事件状态:

setInterval(function(){
if($("span.sapMCrslActive[data-slide=3]").length > 0) {
$('.sapMCrslHud .sapMCrslNext').css('visibility', 'hidden');
}else{
$('.sapMCrslHud .sapMCrslNext').css('visibility', 'visible');
}
}, 50);

关于javascript - 根据另一个元素的数据属性隐藏一个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41380229/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com