jQuery mouseenter +鼠标离开+单击以更改 3
我有一组 3 个
,我需要更改 mouseenter、mouseleave 和 click< 上每个的类/强>。到目前为止,一切正常,除了当我单击时,第三个
不会停留在 mouseenter 状态。它消失了。代码:
$(function(){
$(".hidden").hide();
$(function(){
$("#list ul li").mouseenter(function(){
$(this).parent().children().first().addClass('name');
$(this).parent().children().next().addClass('title');
$(this).parent().children().last().show().addClass('award');
}).mouseleave(function(){
$(this).parent().children().first().removeClass('name');
$(this).parent().children().next().removeClass('title');
$(".hidden").hide();
}).click(function(e){
$('.perm-name').removeClass('perm-name');
$('.perm-title').removeClass('perm-title');
$('.perm-award').removeClass('perm-award');
$(this).parent().children().first().addClass('perm-name');
$(this).parent().children().next().addClass('perm-title');
$(this).parent().children().last().show().addClass('perm-award');
});
$("#list ul li").first().trigger('mouseenter');
});
CSS:
.name,.perm-name { color:#454444; }
.title,.perm-title { color:#930303; }
.award,.perm-award { color:#454444; font-size:11px;}
HTML:
<div id="list">
<ul>
<li>THE KILLERS.</li>
<li>WHEN WE WERE YOUNG</li>
<li class="hidden">(2006 Grammy Nominated, Best Long Form Video of the Year)</li>
</ul>
<ul>
<li>COMMON.</li>
<li>TESTIFY</li>
<li class="hidden">(2005 Music Award Nominated, Director of the Year)</li></
</ul>
<ul>
<li>DURAN DURAN.</li>
<li>FALLING DOWN extended version</li>
<li class="hidden">(2008 Music Award Nominated, Video of the Year)></li>
</ul>
<ul>
<li>ARTFUL DODGER.</li>
<li>short film</li>
<li class="hidden">(2004 Music Award Nominated, Director of the Year)></li>
</ul>
</div>
I have a set of 3 <li>
that I need to change the class of each on mouseenter, mouseleave and click.
So far everything is working except when I click, the 3rd <li>
doesn't stay in the mouseenter state. It disappears.
click here to see how it works so far
CODE:
$(function(){
$(".hidden").hide();
$(function(){
$("#list ul li").mouseenter(function(){
$(this).parent().children().first().addClass('name');
$(this).parent().children().next().addClass('title');
$(this).parent().children().last().show().addClass('award');
}).mouseleave(function(){
$(this).parent().children().first().removeClass('name');
$(this).parent().children().next().removeClass('title');
$(".hidden").hide();
}).click(function(e){
$('.perm-name').removeClass('perm-name');
$('.perm-title').removeClass('perm-title');
$('.perm-award').removeClass('perm-award');
$(this).parent().children().first().addClass('perm-name');
$(this).parent().children().next().addClass('perm-title');
$(this).parent().children().last().show().addClass('perm-award');
});
$("#list ul li").first().trigger('mouseenter');
});
CSS:
.name,.perm-name { color:#454444; }
.title,.perm-title { color:#930303; }
.award,.perm-award { color:#454444; font-size:11px;}
HTML:
<div id="list">
<ul>
<li>THE KILLERS.</li>
<li>WHEN WE WERE YOUNG</li>
<li class="hidden">(2006 Grammy Nominated, Best Long Form Video of the Year)</li>
</ul>
<ul>
<li>COMMON.</li>
<li>TESTIFY</li>
<li class="hidden">(2005 Music Award Nominated, Director of the Year)</li></
</ul>
<ul>
<li>DURAN DURAN.</li>
<li>FALLING DOWN extended version</li>
<li class="hidden">(2008 Music Award Nominated, Video of the Year)></li>
</ul>
<ul>
<li>ARTFUL DODGER.</li>
<li>short film</li>
<li class="hidden">(2004 Music Award Nominated, Director of the Year)></li>
</ul>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个完整的 HTML 页面,其中包含您正在寻找的功能:
您不需要太多 jQuery - 您应该在继续工作之前看一些有关 HTML 和 CSS 的书籍,这会为您省去很多麻烦。
Here's a full HTML page with the functionality you're looking for:
You're not looking for much jQuery - you should take a look at some books on HTML and CSS before continuing your work, it'll save you a lot of headaches.
为什么要将一个 document.ready 放在另一个 document.ready 中
如果您想在 page 中添加两个 document.ready 函数,
。你应该这样做
,为什么你在这里使用两个 document.ready 函数............ ???
why do you have one document.ready inside another one
if you want to add two document.ready functions in page .
you should do it like this
and also why are you using two document.ready functions here............. ???