Css 在菜单中为过渡添加下划线
我有一个带有熔岩灯状下划线的菜单,如下所示:Css 在菜单中为过渡添加下划线,css,focus,css-transitions,Css,Focus,Css Transitions,我有一个带有熔岩灯状下划线的菜单,如下所示: 单击链接时,下划线会在链接之间滑动。试试JSFIDLE 我唯一的问题是,如果在菜单外单击,下划线会恢复到原来的状态(18%)。但是当你在菜单外点击时,我希望下划线保持在上次点击的链接上 我尝试了:访问了,但它什么也没做。你可以通过CSS来实现这一点,我真的不知道。 但是为什么不使用这3行JS(jQuery)并用以下内容替换样式定义: $('.ph-line-nav').on('click', 'a', function() { $('.ph
单击链接时,下划线会在链接之间滑动。试试JSFIDLE 我唯一的问题是,如果在菜单外单击,下划线会恢复到原来的状态(18%)。但是当你在菜单外点击时,我希望下划线保持在上次点击的链接上
我尝试了
:访问了,但它什么也没做。你可以通过CSS来实现这一点,我真的不知道。
但是为什么不使用这3行JS(jQuery)并用以下内容替换样式定义:
$('.ph-line-nav').on('click', 'a', function() {
$('.ph-line-nav a').removeClass('active');
$(this).addClass('active');
});
nav a:nth-child(1).active ~ .effect {
left: 18%;
/* the middle of the first <a> */
}
nav a:nth-child(2).active ~ .effect {
left: 43.5%;
/* the middle of the second <a> */
}
$('.ph line nav')。在('click','a',function()上{
$('.ph line nav a').removeClass('active');
$(this.addClass('active');
});
导航a:第n个孩子(1)。主动~效果{
左:18%;
/*第一部分的中间部分我真的不知道,你可以通过CSS来实现这一点。
但是为什么不使用这3行JS(jQuery)并用以下内容替换样式定义:
$('.ph-line-nav').on('click', 'a', function() {
$('.ph-line-nav a').removeClass('active');
$(this).addClass('active');
});
nav a:nth-child(1).active ~ .effect {
left: 18%;
/* the middle of the first <a> */
}
nav a:nth-child(2).active ~ .effect {
left: 43.5%;
/* the middle of the second <a> */
}
$('.ph line nav')。在('click','a',function()上{
$('.ph line nav a').removeClass('active');
$(this.addClass('active');
});
导航a:第n个孩子(1)。主动~效果{
左:18%;
/*在第一部分的中间部分,您实际上可以使用:target
伪类使用纯css来实现这一点
以下是更新的
注意:您需要一个现代浏览器来使用此方法。(IE9+)
另外,看一下哪个显示了一些用css模拟点击事件的聪明方法(其中之一是:target伪类。您实际上可以使用:target
伪类用纯css来实现这一点
以下是更新的
注意:您需要一个现代浏览器来使用此方法。(IE9+)
另外,看一下哪个显示了一些用css模拟点击事件的聪明方法(其中一个是:target伪类)。我用click
替换了focus
,现在它也在Chrome中工作。也许你可以用这个更新你的答案。这是什么:$('.ph line nav a')。removeClass('active'));行吗?请阅读官方文档:。这是基本jQuery:)我用单击替换了焦点,现在它也在Chrome中工作。也许你可以用这个更新你的答案。这是什么:$('.ph line nav a')。removeClass('active');行吗?请阅读官方文档:。这是基本jQuery:)我需要以IE7+为目标,但这对未来的项目很好!我需要以IE7+为目标,但对未来的项目很好!