js 花瓣自定定义

花瓣自定定义,方便以后使用

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>花瓣</title>
    <style type="text/css">
        .leaf-box {
            display: flex;
            justify-content: center
        }

        .leaf-box .leaf {
            width: 100px;
            height: 100px;
            background-color: #000;
            border-top-left-radius: 5px;
            border-top-right-radius: 5px;
            border-bottom-right-radius: 5px;
            border-bottom-left-radius: 5px;
        }
    </style>
</head>
<body>

<div class="leaf-box">
    <div id="leaf" class="leaf"></div>
</div>
<div id="leafCss"></div>

<div>
    宽:<input id="lw""" type="range" value="100" min="1" max="1080" step="1" />
    <br/>
    高:<input id="lh"" type="range" value="100" min="1" max="1080" step="1" />
    <br/>
    颜色:<input id="lc""" type="color" value="#000"/>
    <br/>
    左上:<input id="lt"" type="range" value="0" min="0" max="100" step="1" />
    <br/>
    左下:<input id="lb"" type="range" value="0" min="0" max="100" step="1" />
    <br/>
    右上:<input id="rt"" type="range" value="0" min="0" max="100" step="1" />
    <br/>
    右下:<input id="rb"" type="range" value="0" min="0" max="100" step="1" />
    <br/>
</div>

<script>

    var leaf = document.querySelector('#leaf');
    var leafCss = document.querySelector('#leafCss');
    var lw = document.querySelector('#lw');
    var lh = document.querySelector('#lh');
    var lc = document.querySelector('#lc');
    var lt = document.querySelector('#lt');
    var lb = document.querySelector('#lb');
    var rt = document.querySelector('#rt');
    var rb = document.querySelector('#rb');

    refreshLeafCss();

    lw.oninput = function() {
        leaf.style.width = lw.value + "px";
        refreshLeafCss();
    }

    lh.oninput = function() {
        leaf.style.height = lh.value + "px";
        refreshLeafCss();
    }

    lc.oninput = function() {
        leaf.style.backgroundColor = lc.value;
        refreshLeafCss();
    }

    lt.oninput = function() {
        leaf.style.borderTopLeftRadius = lt.value + "%";
        refreshLeafCss();
    }

    lb.oninput = function() {
        leaf.style.borderBottomLeftRadius = lb.value + "%";
        refreshLeafCss();
    }

    rt.oninput = function() {
        leaf.style.borderTopRightRadius = rt.value + "%";
        refreshLeafCss();
    }

    rb.oninput = function() {
        leaf.style.borderBottomRightRadius = rb.value + "%";
        refreshLeafCss();
    }

    function refreshLeafCss() {
        var css = '';
        css += "width: " + leaf.style.width + ";";
        css += "height: " + leaf.style.height + ";";
        css += "background-color: " + leaf.style.backgroundColor + ";";
        css += "border-top-left-radius: " + leaf.style.borderTopLeftRadius + ";";
        css += "border-bottom-left-radius: " + leaf.style.borderTopLeftRadius + ";";
        css += "border-top-right-radius: " + leaf.style.borderTopRightRadius + ";";
        css += "border-bottom-right-radius: " + leaf.style.borderBottomRightRadius + ";";
        leafCss.innerHTML = css;
    }


</script>
</body>
</html>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值