利用前端基础制作html开关图标

利用前端基础制作html开关图标

我们先来看下效果图:

df7e11f07057c578f309813574250f0.png

(学习视频分享:html视频教程)

html代码:

立即学习“前端免费学习笔记(深入)”;

    开关图标    

css样式:

        body {            text-align: center        }        .SwitchIcon {            margin: 200px auto;        }        #toggle-button {            display: none;        }        .button-label {            position: relative;            display: inline-block;            width: 80px;            height: 30px;            background-color: #ccc;            box-shadow: #ccc 0px 0px 0px 2px;            border-radius: 30px;            overflow: hidden;        }        .circle {            position: absolute;            top: 0;            left: 0;            width: 30px;            height: 30px;            border-radius: 50%;            background-color: #fff;        }        .button-label .text {            line-height: 30px;            font-size: 18px;            text-shadow: 0 0 2px #ddd;        }        .on {            color: #fff;            display: none;            text-indent: -45px;        }        .off {            color: #fff;            display: inline-block;            text-indent: 34px;        }        .button-label .circle {            left: 0;            transition: all 0.3s;        }        #toggle-button:checked + label.button-label .circle {            left: 50px;        }        #toggle-button:checked + label.button-label .on {            display: inline-block;        }        #toggle-button:checked + label.button-label .off {            display: none;        }        #toggle-button:checked + label.button-label {            background-color: #19e236;        }        .div {            height: 20px;            width: 30px;            background: #51ccee;        }    

js逻辑:

        //窗体加载        window.onload = function () {            var onoffswitch = document.getElementById("toggle-button");            onoffswitch.checked = true;        }        //测试开始        function SwitchClick() {            var onoffswitch = document.getElementById("toggle-button");            var label = document.getElementById("batteryIconContent");            if (onoffswitch.checked) {                //调用后台            }            else {                //调用后台            }        }    

相关推荐:html教程

以上就是利用前端基础制作html开关图标的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1548609.html

赞 (0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
www中的超文本文件是用什么语言编写的
上一篇 2025年12月21日 20:03:53
span是块元素吗?
下一篇 2025年12月21日 20:04:01

相关推荐

发表回复

登录后才能评论
关注微信