按钮实现鼠标悬停背景色渐变的动画特效

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        input {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            text-transform: uppercase;
            width: 200px;
            height: 40px;
            border: 1px solid #000;
            background: -webkit-linear-gradient(90deg, #fff, #fff, #000, #000);
            background:    -moz-linear-gradient(90deg, #fff, #fff, #000, #000);
            background:      -o-linear-gradient(90deg, #fff, #fff, #000, #000);
            background:         linear-gradient(90deg, #fff, #fff, #000, #000);
            background-size: 300% 300%;
            background-position: 1% 50%;
            transition: all 1s ease;
            -webkit-transition: background 0.3s ease;
            -moz-transition: background 0.3s ease;
            -o-transition: background 0.3s ease;
            outline: none;
            cursor: pointer;
        }

        input:hover {
            color: #fff;
            background-position: 99% 50%;
        }
    </style>
</head>
<body>

<input type="button" value="button">



</body>
</html>

这个是利用background-position属性的变化实现的渐变效果

按钮实现鼠标悬停背景色渐变的动画特效


还可以通过box-shadow属性来实现这种动画效果,只是颜色不会有一个平滑的过度

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        body {
            font: 14px/1.5 Arial;
            box-sizing: border-box;
        }

        .btn {
            display: block;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            text-transform: uppercase;
            width: 200px;
            height: 40px;
            text-decoration: none;
            color: #fff;
            text-align: center;
            line-height: 40px;
            border: 1px solid #d91222;
            -moz-box-shadow: 200px 0 #d91222 inset; /*通过正负值调整变化方向*/
            box-shadow: 200px 0 #d91222 inset;
            -webkit-transition: all 0.3s;
            -moz-transition: all 0.3s;
            -o-transition: all 0.3s;
            transition: all 0.3s;
        }
        .btn:hover {
            box-shadow: 0 0 #d91222 inset;
            color: #d91222;
        }
    </style>
</head>
<body>

<div><a href="javascript:void(0)" class="btn">Hover me</a></div>

</body>
</html>
按钮实现鼠标悬停背景色渐变的动画特效

上一篇:电商小程序开发的关键在哪里?


下一篇:再谈虚拟机里快照和扩容问题!