我的网站至少有两个"新闻框",使用的代码如下:
<a class="newsbox" href="#"><span>TITLE</span><div>read more</div></a>
<a class="newsbox" href="#"><span>TITLE</span><div>read more</div></a>
Run Code Online (Sandbox Code Playgroud)
使用此代码,我隐藏了此锚标记中的"read more":
jQuery("a.newsbox div").hide();
Run Code Online (Sandbox Code Playgroud)
哪个工作正常.
现在我想让"阅读更多"仅在当前悬空的新闻框中可见.
我尝试使用此代码:
jQuery("a.newsbox").hover(function() {
jQuery(this).hover(function() {
jQuery("div").fadeIn();
});
});
Run Code Online (Sandbox Code Playgroud)
但这适用于所有带有"newsbox"类的锚标签.如何选择当前元素并仅显示当前悬停元素的"读取更多"?
尝试这样的事情:
$('a.newsbox').hover( function(){
$(this).find('div').fadeToggle();
});
Run Code Online (Sandbox Code Playgroud)
通过使用fadeToggle,"read more"也将隐藏在mouseout上.