zoukankan      html  css  js  c++  java
  • 利用CSS变量实现悬浮效果

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
    </head>
    
    <style>
        .button {
            position: relative;
            appearance: none;
            background: #f72359;
            padding: 10px 200px;
            border: none;
            color: white;
            font-size: 1.2em;
            cursor: pointer;
            outline: none;
            overflow: hidden;
            border-radius: 100px;
        }
        
        span {
            position: relative;
        }
        
        .button::before {
            --size: 0;
            content: '';
            position: absolute;
            left: var(--x);
            top: var(--y);
             var(--size);
            height: var(--size);
            background: radial-gradient(circle closest-side, #4405f7, transparent);
            transform: translate(-50%, -50%);
            transition: width .2s ease, height .2s ease;
        }
        
        .button:hover::before {
            --size: 400px;
        }
    </style>
    
    <body>
        <button class="button"><span>点击</span></button>
    </body>
    
    </html>
    <script>
        document.querySelector('.button').onmousemove = (e) => {
    
            const x = e.pageX - e.target.offsetLeft
            const y = e.pageY - e.target.offsetTop
    
            e.target.style.setProperty('--x', `${ x }px`)
            e.target.style.setProperty('--y', `${ y }px`)
    
        }
    </script>
    

      

  • 相关阅读:
    使用video.js支持flv格式
    微信小程序开发(一)
    python advanced programming ( II )
    python advanced programming ( I )
    HTML/CSS
    info AI drive
    python基础回顾
    计算机组成原理2
    6.00.1x Introduction to computation
    有一种感动叫ACM(记陈立杰在成都赛区开幕式上的讲话)
  • 原文地址:https://www.cnblogs.com/duke-peng/p/8978671.html
Copyright © 2011-2022 走看看