【发布时间】:2019-09-18 08:43:12
【问题描述】:
对不起,如果我的问题太愚蠢或不相关,但我在 jquery 中是如此的新手......无论如何,我正在尝试在幻灯片的父 div 上添加一些背景字母(带有 :before 伪元素)基于 aria-hidden 值...
这是一个托管的 cms(一种 DIY 网站构建器),我无法访问 html,但只能访问网站的 head 部分。因此,在父 div 中,我在左侧有一些内容(标题、文本、按钮),在右侧有预安装的幻灯片 - 幻灯片具有 ul 和 li 的常规结构,但是没有任何“活动”类可见幻灯片 - 我检测到的唯一变化是所有 li 都有 aria-hidden="true" 而可见的(活动的)更改为 aria-hidden="false",所以我必须坚持这个......在父级上添加我的 :before 伪元素。
CSS
.brandName:before{
content: 'BRAND NAME';
color: #d2dbdc;
position: absolute;
left: 50%;
top: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-o-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
opacity: 0.6;
font-family: "Lato",sans-serif,"google";
font-weight: 700;
letter-spacing: 5vw;
font-size: 7vw;
z-index: -1;
}
HTML
<div class="landing-section">
<div class="left-side">
<h1>Some Heading</h1>
<p>Some text</p>
<button>Some Button</button>
</div>
<div class="right-side">
<div id="cc-m-gallery-7739661064" class="cc-m-gallery-container cc-m-gallery-slider ">
<div class="bx-wrapper" style="max-width: 100%;">
<div class="bx-viewport" aria-live="polite" style="width: 100%; overflow: hidden; position: relative; height: 583px;">
<ul style="width: 9215%; position: relative; transition-duration: 0s; transform: translate3d(-560px, 0px, 0px);">
<li aria-hidden="true" style="float: left; list-style: none; position: relative; width: 558px; margin-right: 2px;" class="bx-clone" >
<img src="https://image/path/cms/image.png" data-orig-width="650" data-orig-height="680" alt="" style="height: 583.247px;">
</li>
<li aria-hidden="false" style="float: left; list-style: none; position: relative; width: 558px; margin-right: 2px;" >
<a href="/products/"><img src="https://image/path/cms/image.png" data-orig-width="650" data-orig-height="680" alt="thatBrand is super" style="height: 583.247px;"><div class="bx-caption" style="width: 533.516px; margin-left: 12px;"><span>thatBrand is super</span></div></a>
</li>
<li aria-hidden="true" style="float: left; list-style: none; position: relative; width: 558px; margin-right: 2px;">
<a href="/products/"> <img src="https://image/path/cms/image.png" data-orig-width="650" data-orig-height="680" alt="another brand image" style="height: 583.247px;"><div class="bx-caption"><span>another brand image</span></div> </a>
</li>
<li aria-hidden="true" style="float: left; list-style: none; position: relative; width: 558px; margin-right: 2px;">
<img src="https://image/path/cms/image.png" data-orig-width="650" data-orig-height="680" alt="" style="height: 583.247px;">
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
我尝试过类似的方法,但没有奏效...有什么想法吗?
$('.cc-m-gallery-slider ul li:has(img[alt*="thatBrand"])').addClass('thatBrand-image');
if ( $('li .thatBrand-image').is('[aria-hidden="false"]') ) {
$('.landing-section').hasClass("brandName");
$('.landing-section').addClass("brandName");
} else {
$('.landing-section').removeClass("brandName");
}
【问题讨论】:
-
您的问题和您的代码有点难以理解。据我所知,您的最终目标是将
::before伪元素文本添加到div.landing-section,但前提是子li元素包含aria-hidden=false。我有这个权利吗? -
@Josh,没错,是的!很抱歉我的问题和代码一团糟,但是我试图尽可能详细...
标签: jquery attributes accessibility