超炫的按钮


超炫的按钮

代码

css:

<style>
    .button-css{
        margin:200px 500px;
        width: 400px;
        position: relative;
        appearance: none;
        background: #f72359;
        padding: 1em 2em;
        border: none;
        color: white;
        font-size: 1.2em;
        cursor: pointer;
        outline: none;
        overflow: hidden;
        border-radius: 100px;
    }
    span {
        position: relative;
    }
    .button-css::before {
        --size: 0;

        content: '';
        position: absolute;
        left: var(--x);
        top: var(--y);
        width: var(--size);
        height: var(--size);
        background: radial-gradient(circle closest-side, #4405f7, transparent);
        transform: translate(-50%, -50%);
        transition: width .2s ease, height .2s ease;
    }
    :hover::before {
        --size: 400px;
    }

</style>

html:

<button class="button-css"><span>Hover me</span></button>

script:

<script>
    $(function () {
        $(".button-css").mousemove(function(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>

效果图:


文章作者: Rabbit
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Rabbit !
 上一篇
js的基础内容 js的基础内容
一.简介1.1 联系与区别 HTML 定义了网页的内容 CSS 描述了网页的布局 JavaScript 网页的行为 1.2 用法 HTML中的脚本必须位于<script></script>标签之间; 脚本可
2018-05-15
下一篇 
jquery-随笔 jquery-随笔
#jquery-笔记(仅作者观看) 语法写法 $(this).hide()-隐藏当前元素 $("p").hide()-隐藏所有的<p>元素 文档就绪事件 为防止文档在完全加载之前运行jquery代码,把jq
2018-05-09
  目录