前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >JS示例01-鼠标移入移出事件

JS示例01-鼠标移入移出事件

作者头像
专注APP开发
发布2019-11-07 15:27:30
5.6K0
发布2019-11-07 15:27:30
举报
文章被收录于专栏:移动大前端

一、知识要点

1、匿名函数 2、鼠标事件 3、document.getElementById() 4、window.onload 5、行间事件提取

二、源码参考

代码语言:javascript
复制
<!DOCTYPE >
<html>

    <head>
        <title></title>
        <meta charset="utf-8">
        <style>
            #div1 {
                width: 200px;
                height: 100px;
                background-color: #ccc;
                border: 1px solid #999;
                display: none;
            }
        </style>
        <script>
            window.onload = function() {
                var input1 = document.getElementById('input1');
                var div1 = document.getElementById('div1');
                input1.onmouseover = function() {
                    div1.style.display = 'block';
                }
                input1.onmouseout = function() {
                    div1.style.display = 'none';
                }
            }
        </script>
    </head>

    <body>
        <input id="input1" type="checkbox" value="checkbox" />
        <div id="div1">
            为了您的信息安全...
        </div>
    </body>

</html>

三、运行效果

image

分享隐藏显示

代码语言:javascript
复制
<!DOCTYPE HTML>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    <style>
        #div1 {
            width: 100px;
            height: 200px;
            background: red;
            position: absolute;
            left: -100px;
            top: 100px;
        }

        #div2 {
            width: 30px;
            height: 60px;
            position: absolute;
            right: -30px;
            top: 70px;
            background: black;
            color: white;
            text-align: center;
        }
    </style>
    <script>
        window.onload = function () {

            var oDiv = document.getElementById('div1');

            oDiv.onmouseover = function () {
                this.style.left = '0px';
            }

            oDiv.onmouseout = function () {
                this.style.left = '-100px';
            }

        }
    </script>
</head>

<body>
    <div id="div1">
        <div id="div2">分享到</div>
    </div>
</body>

</html>

image

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、知识要点
  • 二、源码参考
  • 三、运行效果
  • 分享隐藏显示
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档