html怎么做向下的图标,如何利用前端基础制作html开关图标

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

发布时间:2020-11-18 11:08:50

来源:亿速云

阅读:108

作者:小新

小编给大家分享一下如何利用前端基础制作html开关图标,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!

我们先来看下效果图:

1dccdb2067cb9460fc4fe2400de0d8b7.png

html代码:

开关图标

ON

OFF

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开关图标有了一定的了解,想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值