利用前端基础制作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中label的作用和使用方法(附代码)

Html s标签怎么用

Html图片失真怎么办

怎么修改Html文件

Html表格线怎么去掉

Html的文字图片怎样垂直居中

javascript作用域的全面解析(附代码)

Html的基本结构有哪些

Html基础知识

Html的盒模型详解

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




打赏

取消

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

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

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

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

评论

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

    暂无评论...