要求:鼠标移入显示提示信息框;鼠标离开,信息框消失,消失的效果延迟

1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <meta name="viewport" content="width=device-width, initial-scale=1.0">
 6     <meta http-equiv="X-UA-Compatible" content="ie=edge">
 7     <title>Document</title>
 8     <style>
 9         #sign{
10             display: inline-block;
11             width: 15px;
12             height: 15px;
13             border: 1px solid #ccc2c2;
14         }
15         #tip{
16             width: 150px;
17             height: 70px;
18             ">);
19             border: 1px solid orange;
20             color: rgb(161, 59, 48);
21             display: none;
22             opacity: 1;
23         }
24     </style>
25 </head>
26 <body>
27     <span id="sign"></span>
28     <span>自动登录</span>
29     <div id="tip">为了您的安全请不要在网吧等公共场所使用!</div>
30 </body>
31 <script>
32     var osign = document.getElementById("sign");
33     var tip = document.getElementById("tip");
34     var timer;
35     var oo=1;
36     //鼠标移入时显示提示信息(让提示框的隐藏效果消失)
37     osign.onmouseover = function(){
38             //清除延时器以免出现闪烁
39             clearInterval(timer);
40             tip.style.display = "block";
41             tip.style.opacity=1;
42     }
43 
44     //鼠标离开,信息消失,隐藏效果延迟
45     osign.onmouseout = function(){
46         clearInterval(timer);
47         timer = setInterval(function(){
48             //让透明度渐减,直至为零
49             oo -= 0.1;
50             tip.style.opacity=oo;
51                 if(oo == 0){
52                     clearInterval(timer);
53                 }
54             },70);
55             //最后复原透明度,成为下次的开始值
56             oo=1;
57     }
58 </script>
59 </html>

转载于:https://www.cnblogs.com/lee1-w/p/11410410.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现鼠标移入 entity 显示 label 信息提示,移出时提示消失,可以按照以下步骤进行: 1. 在 Vue 组件中引入 Cesium 库: ```javascript import Cesium from 'cesium/Cesium'; import 'cesium/Widgets/widgets.css'; ``` 2. 在 `mounted` 钩子函数中初始化 Cesium 以及创建 viewer: ```javascript mounted() { // 初始化 Cesium this.viewer = new Cesium.Viewer(this.$refs.cesiumContainer, { geocoder: false, homeButton: false, sceneModePicker: false, navigationHelpButton: false, animation: false, timeline: false }); } ``` 3. 在 `created` 钩子函数中创建要显示的 entity 和 label: ```javascript created() { // 创建要显示的 entity 和 label const position = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883); const entity = this.viewer.entities.add({ position: position, point: { pixelSize: 10, color: Cesium.Color.YELLOW } }); entity.label = { text: 'Hello, world!', show: false, showBackground: true, font: '14px monospace', style: Cesium.LabelStyle.FILL_AND_OUTLINE, outlineWidth: 2, verticalOrigin: Cesium.VerticalOrigin.BOTTOM, pixelOffset: new Cesium.Cartesian2(0, -9) }; } ``` 4. 在 `mounted` 钩子函数中添加鼠标移入和移出事件监听器: ```javascript mounted() { // ... // 添加鼠标移入和移出事件监听器 this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas); this.handler.setInputAction(event => { const pickedObject = this.viewer.scene.pick(event.endPosition); if (Cesium.defined(pickedObject) && pickedObject.id === entity) { entity.label.show = true; } }, Cesium.ScreenSpaceEventType.MOUSE_MOVE); this.handler.setInputAction(event => { entity.label.show = false; }, Cesium.ScreenSpaceEventType.LEFT_CLICK); } ``` 这样,当鼠标移动到 entity 上时,label 信息提示显示出来,移出时会消失。其中 `entity` 是在第三步中创建的,需要在第四步中使用。同时需要注意,要在组件销毁时清除事件监听器: ```javascript beforeDestroy() { // 清除事件监听器 this.handler.destroy(); this.viewer.destroy(); } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值