gpt4 book ai didi

javascript - 在父 div 之后查找 css 类

转载 作者:行者123 更新时间:2023-11-30 11:50:21 24 4
gpt4 key购买 nike

有任何 jquery 在父 div 之后查找类,我正在使用类“trapezoid-two”并制作 jquery 代码但是这会产生问题,所以任何人都可以告诉我如何在父 div 类之后找到 css('ban -menu1').

HTML:-

<div class="col-md-2 nopadding">
<div class="ban-menu1"></div>
<svg class="trapezoid-two" viewbox="0 0 100 100" preserveAspectRatio="none" width="100%">
<defs>
<pattern id="img1" patternUnits="userSpaceOnUse" width="100" height="100">
<image xlink:href="images/shade-two.jpg" x="0" y="0" width="110" height="100" />
</pattern>
</defs>
<path d="M0,0 L100,23 L100,77 L0,100z" fill="url(#img1)"></path>
</svg>
</div>

查询

$(document).ready(function(){   
$( ".trapezoid-two" ).hover(
function() {
$(this).find('path').attr('d','M0,0 L100,0 L100,100 L0,100z');
$(this).parent().addClass('img-scale');
}, function() {
$(this).find('path').attr('d','M0,0 L100,23 L100,80 L0,100z');
$(this).parent().removeClass('img-scale');
}
);
});

最佳答案

ban-menu1.trapezoid-two 的兄弟,使用 prev() 来帮助您向其添加类

$(document).ready(function(){
// svg path change
$( ".trapezoid-two" ).hover(
function() {
$(this).find('path').attr('d','M0,0 L100,0 L100,100 L0,100z');
$(this).prev().addClass('img-scale');
}, function() {
$(this).find('path').attr('d','M0,0 L100,23 L100,80 L0,100z');
$(this).prev().removeClass('img-scale');
}
);

查看演示:https://jsfiddle.net/cgvbt80q/

关于javascript - 在父 div 之后查找 css 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39653550/

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