您可以使用jQuery的短代碼,這樣
$('.animate').mouseenter(function() {
$(this).addClass('filled');
}).mouseout(function() {
$(this).removeClass('filled')
})
而且通過CSS
.animate{
display: inline-block;
height: auto!important;
width: 200px;
background: #bbb;
position: relative;
}
.animate:before {
content: '';
position: absolute;
left: 0;
top: 0;
height: 100%;
background: red;
width: 0;
transition: all .5s ease;
}
.animate.filled:before{
width: 100%;
}
input {
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
width: 100%;
-webkit-appearance: none;
appearance: none;
background: none;
border: none;
}
HTML操縱filled
類:
<form>
<div class="animate"><input value="Send" type="submit" class="brtel"></div>
</form>
選中此筆:http://codepen.io/todorutandrei/pen/MeKQze
這就是我想要的,很好的解決方案。 –