如何将图像选择到锚中以应用jQuery事件
当点击h1时,我正试图将图像淡入我的垂直菜单中的a。 但没有找到正确的方法。 我能得到的最远的是褪色,但不是特定的图像。 我的问题是如何做到这一点,哪个jquery选择器组合可以选择那些图像进入锚点。 我的意图是淡化那些图像并再次使用其他动作(事件)淡出,例如当我点击相同结构中的其他元素时。 您可以在这里查看我的进展www.miramarlab.com/index222.htm
这是我的结构:
这是我使用jquery的适度意图:
$(function() { $('#categories h1').click( function () { $(this).removeClass('hover').addClass('active'); $('#categories h1').not(this).removeClass('active').addClass('normal'); $(this).parents('div:eq(1)').stop().animate({'width':'488px'},500); $(this).next().stop(true,true).slideDown(500); // thi is my intent ;) $(this).siblings().children('img').stop(true,true).fadeOut(500); var siblings = $(this).parents('div:eq(1)').siblings() siblings.stop().animate({'width':'152px'},500); $('.description',siblings).stop(true,true).slideUp(500); } ); });
先谢谢你们!
爬起来然后退下来。
$(this).closest('.trans').find('img').stop(true,true).fadeOut(500);
这一直是目标forms的安全模式。
1)从问题元素$(this)
或者将其缓存以便重复使用var $header = $(this)
2)使用.closest()遍历“组容器”
3)使用.find()深入查看感兴趣的元素
这样,您的代码将更可重用,并且更能抵抗html中的微小更改
img
元素不是ul
子元素(它们是更深层次的后代),这就是你当前代码无效的原因。 尝试:
$(this).siblings().find('li img').stop(true,true).fadeOut(500);