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


当前第2页 返回上一页

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

<style type="text/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;

        }

    </style>

js逻辑:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

<script type="text/javascript">

        //窗体加载

        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 {

                //调用后台

            }

        }

    </script>

相关推荐:html教程

以上就是利用前端基础制作html开关图标的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

Html中的title是什么意思?

Html格式化json的实例代码

Html中的document对象是什么?一篇文章让你了解document对象

Html与css中的过渡模块

Html div边框线怎么设置

Html abbr标签是什么意思?Html abbr标签的具体用法详解

Html实现页面点击下载文件的两种实现方法

图文详解<img>标签中alt属性和title属性的区别

Html和asp之间的区别是什么

Html如何转pdf

更多相关阅读请进入《Html》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...