运动——对联悬浮框

代码:<!DOCTYPE HTML><html><head>    <meta charset="utf-8">    <title>无标题文档</title>    <style>        #div {            width: 100px;            height: 150px;            background: red;            position: absolute;            right: 0;            bottom: 0;        }    </style>    <script>        // window.onscroll 滚动页面时触发        window.onscroll=function() {            var oDiv = document.getElementById("div");            var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;//一般只用前者            startMove(parseInt((document.documentElement.clientHeight - oDiv.offsetHeight) / 2 + scrollTop));            //clientHeight:内容可视区域的高度,其中变量主要表示高度在页面浏览器所能看到的区域中央        };        var  timer=null;//timer一定要放在函数外,clearInterval(timer)才能起作用

        function startMove(iTarget){               var oDiv = document.getElementById("div");

               clearInterval(timer);//保证函数中永远只有一个定时器,防止效果叠加,比如运动不断加速或透明度不断加大               timer=setInterval(function(){                   var speed=(iTarget-oDiv.offsetTop)/4;//4 只是用来设置速度快慢,可以自定义(越大速度越慢)                   speed=speed>0?Math.ceil(speed):Math.floor(speed);                   //Math.ceil():向上取整;Math.floor()向下取整;取整speed是为了防止speed和iTarget有误差而导致窗口在悬浮位置抖动                   if(oDiv.offsetTop==iTarget){                       clearInterval(timer);                   }else{                       document.title=iTarget;//获取当前目标的值                       document.getElementById("txt").value=oDiv.offsetTop;                       oDiv.style.top=oDiv.offsetTop+speed+‘px‘;

                   }               },30);

        }    </script></head>

<body style="height:2000px;"><input type="text" id="txt" style="position:fixed; right:0; top:0;"/>

<div id="div"></div></body></html>运行结果:  初始界面:           不断滑动页面滚动条之后界面:          
时间: 2024-07-29 07:17:28

运动——对联悬浮框的相关文章

(41)JS运动之右侧中间悬浮框(对联悬浮框)

<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title></title> <style> #div1{ width:100px; height:150px; background:red; position:absolute; right:0; bottom:0; } </style> <script> windo

(40)JS运动之右下角悬浮框

<!DOCTYPE HTML> <!-- --> <html> <head> <meta charset="utf-8"> <title></title> <style> #div1{ width:100px; height:150px; background:red; position:absolute; right:0; bottom:0; } </style> <s

“右侧悬浮框”页面特效

功能描述: 悬浮框固定在页面右下方,随着滚动条的滚动,悬浮框运动到固定位置. 实现效果: 编码思路: 获取滚动条滚动时,方块需要移动的目标位置(可视区域的高度-物体高度-滚动的高度). 套用运动框架. 示例代码:

JavaScript侧边悬浮框

<script> window.onscroll=function(){ var oDiv=document.getElementById('div1'); var scrollTop=document.documentElement.scrollTop||document.body.scrollTop; oDiv.style.top=(document.documentElement.clientHeight-oDiv.offsetHeight)/2+scrollTop+'px'; star

小米Adnroid默认禁止悬浮框的使用,导致开发的悬浮框无法接收事件

比如你建了一个悬浮框: WindowManager windowManager = getWindowManager(context); int screenWidth = windowManager.getDefaultDisplay().getWidth(); if (smallWindow == null) { smallWindow = new FloatWindowSmallView(context); if (smallWindowParams == null) { smallWin

js实现页面悬浮框

当滚动条下拉时,悬浮框位置不变,主要是 position:fixed;样式的作用. 当下拉到一定程度,接近footer时,我用js控制div消失,往上拉滚动条时又显示. <!DOCTYPE html> <html> <head> <title></title> <style type="text/css"> .div1 { height:2000px; } .div2 { width:100%; height:35

android悬浮框的使用

实质就是开启一个界面透明的activity 注意:在startService 想在startActivity intent必须要设置addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 直接上Demo---myFloat http://pan.baidu.com/s/1gdIK4QR android悬浮框的使用

悬浮框

1. 右侧底部悬浮框 运行效果图: [http://runjs.cn/code/zvjocat0] 要点:oDiv.style.top=document.documentElement.clientHeight-oDiv.offsetHeight+scrollTop; 2. 右侧中部悬浮框 运行效果图:[http://runjs.cn/code/bws1gmne] 要点: oDiv.style.top=Math.ceil((document.documentElement.clientHeigh

使用悬浮框监听内存的使用状态 -- 附源码

源码下载地址:http://download.csdn.net/detail/hewence1/8176601 <span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">先看一下效果:  显示当前内存使用率55% ,每一秒都刷新一次</span> 实现原理,在Service中创建一个悬浮框就可,在service中每秒钟访问计算一次单