【发布时间】:2012-12-25 00:46:56
【问题描述】:
我正在创建一个链接,当单击该链接时,它会向下移动几个像素。 我希望这是一个动画,所以我添加了 CSS 过渡。 现在我遇到的问题是当我按下按钮时,它没有完成动画。 只要我按住鼠标按钮,它就会动画。
所以我想要的是链接完成它的动画,然后回到正常位置。 (这意味着我不能使用 :visited 因为它不会恢复正常)。
这是我为了澄清我的问题而做的一个小提琴:
这是我正在使用的代码:
css
.button
{
font-size: 132px;
font-family: helvetica, sans;
font-weight: bold;
text-shadow: 0px 7px 0px #3b6e62;
color: #f2b191;
text-align:center;
padding-top: 46px;
padding-top:0px;
-webkit-transition: all 0.4s ease-in-out; -moz-transition: all 0.4s ease-in-out; -ms-transition: all 0.4s ease-in-out; -o-transition: all 0.4s ease-in-out; transition: all 0.4s ease-in-out;
}
.button:hover {padding-top:3px; text-shadow: 0px 4px 0px #3b6e62;}
.button:active {padding-top:7px; text-shadow: 0px 0px 0px #3b6e62;}
html
<div class="button">This is a button</div>
我愿意用 jquery 解决问题,但我不是专家。
我刚刚通过使用 jQuery 找到了一条出路。 但是,我不确定这是正确的方法。 动画不像 css 伪类那样流畅..
有人对此有什么要补充的吗?
$('.button').hover(function(){
$(this).css({'top': '3px', 'text-shadow': '0px 4px 0px #3b6e62'});
});
$('.button').click(function(){
$(this).css({'top': '7px', 'text-shadow': '0px 0px 0px #3b6e62'});
});
$('.button').mouseout(function(){
$(this).css({'top': '0px', 'text-shadow': '0px 7px 0px #3b6e62'});
});
【问题讨论】:
标签: css css-transitions pseudo-class