简体   繁体   English

选择THIS元素的第1个第2个和第3个子元素

[英]Select 1st 2nd and 3rd child element of THIS element

I have two links that show and hide different divs. 我有两个链接显示和隐藏不同的div。 The divs have 3 elements h2, p and img and I would like to animate each element separately but can't seem to figure out how. div有3个元素h2,p和img,我想分别为每个元素制作动画,但似乎无法弄清楚如何。

I would like to click on a link and make each element have a different animation for entrance and leaving. 我想点击链接,让每个元素都有不同的动画进入和离开。 I am pasting my html and jQuery here hope someone can help. 我在粘贴我的HTML和jQuery,希望有人可以提供帮助。

 function showonlyone1(thechosenone) { $('.uslugetxt').each(function(index) { if ($(this).attr("id") == thechosenone) { $(this).fadeTo("slow", 1); $(this).children().animate({ fontSize: "50" }, 500) } else { $(this).fadeTo("slow", 0); $(this).children().animate({ fontSize: "0" }, 500) } }); } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="sidebarmenu"> <a href="javascript:showonlyone1('x1');">analitycs</a> <a href="javascript:showonlyone1('x2');">PPC campaigns</a> </div> <div class="uslugetxt" id="x1" class="x1"> <h2 class="naslovx">GOOGLE ANALITYCS</h2> <p> There is something funny about your data? You double question </p> <img src="imgs/analitika.jpg" alt="analitika-slika"> </div> <div class="uslugetxt" id="x2" class="x2"> <h2 class="naslovx">DISPLAY ADVERTISING</h2> <p> Display Advertising is partially covered through content Social networks like Facebook, Twitter, MySpace, LikedIn, </p> <img src="imgs/decasocial.jpg" alt="analitika-slika"> </div> 

try using the :nth() pseudo selector? 尝试使用:nth()伪选择器?

 showonlyone1 = function showonlyone1(thechosenone) { $('.uslugetxt').each(function(index) { if ($(this).attr("id") == thechosenone) { $(this).fadeTo( "slow", 1 ); $(this).children(":nth(0)").animate({fontSize: "50"}, 500, function(){ $(this).parent().children(":nth(1)").animate({fontSize: "30"}, 500) }) } else { $(this).fadeTo( "slow", 0 ); $(this).children().animate({fontSize: "0"}, 500) } }); } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="sidebarmenu"> <a href="javascript:showonlyone1('x1');">analitycs</a> <a href="javascript:showonlyone1('x2');">PPC campaigns</a> </div> <div class="uslugetxt" id="x1" class="x1"> <h2 class="naslovx">GOOGLE ANALITYCS</h2> <p> There is something funny about your data? You double question </p> <img src="imgs/analitika.jpg" alt="analitika-slika"> </div> <div class="uslugetxt" id="x2" class="x2"> <h2 class="naslovx">DISPLAY ADVERTISING</h2> <p> Display Advertising is partially covered through content Social networks like Facebook, Twitter, MySpace, LikedIn, </p> <img src="imgs/decasocial.jpg" alt="analitika-slika"> </div> 

Now for your next question, how to time animations, simply use the complete function of the animation. 现在为您的下一个问题,如何定时动画,只需使用动画的完整功能。 So when my first animation completes, the second runs -- but bear in mind that, in the context of the completed function, 'this' refers to the animated element! 因此,当我的第一个动画完成时,第二个动画完成 - 但请记住,在完成的函数的上下文中,'this'指的是动画元素! We'll go back to its parent, select the next child, and animate THAT. 我们将返回其父级,选择下一个孩子,然后设置动画。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 隐藏在第一和第二选择列表中选择的第三选择列表的选项 - Hide option of 3rd select list which are selected in 1st and 2nd select list Select 每个元素三元组中的第二个和第三个元素 - Select 2nd and 3rd element from each triplet of elements 在第一个数组元素中的第二个数组元素中查找字母 - Finding letters in 2nd array element in 1st array element Puppeteer 打开下拉菜单,然后单击 [1st 2nd 3rd…] 选项 - Puppeteer Open Dropdown Menu and then click on [1st 2nd 3rd…] option 删除查询第一次未触发,第二次或第三次触发 - Delete query didn't fired on 1st time,it fired after 2nd or 3rd time 我的滑块仅显示第1和第3个滑块,但不显示表格的第2和第4个滑块 - My slider only shows 1st and 3rd slider but not the 2nd and 4th slider for table 如何更改数组中的每个第二个和第三个元素? - How to change every 2nd and 3rd element in an array? 如何在选项标签 select 下拉列表 1st 2nd 3rd 4th 5th 中添加上标。 1ST 我想要 S 大写字母,但我试过 s 将转换为小写 - How to add superscript in option tag select dropdown 1st 2nd 3rd 4th 5th. 1ST I want S captial letters but i tried s will converted to small case 如何在单击时播放第一个音频,在第二次单击时播放第二个音频,在第三次单击时播放第三个音频,Jquery - How to play 1st Audio on click, 2nd audio on second click, 3rd audio on third click, Jquery 儿童元素的AngularJS动画第一次,第二次失败 - AngularJS animate on children element works 1st time, 2nd fails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM