JS-缓冲运动-对联型悬浮框
<!DOCTYPE html>
<html> <head>
<meta charset="UTF-8">
<title>缓冲运动2</title>
<style type="text/css">
body{
height: 2000px;
}
.div {
width: 100px;
height: 100px;
background-color: darkslateblue;
position: absolute;
right: 0;
/*bottom: 0;*/
cursor: pointer;
}
</style>
<script type="text/javascript">
window.onscroll= function(){
//1,给浏览器的滚动添加事件,onscollTop事件
var oDiv = document.getElementById('div');
var scrollTop = document.documentElement.scrollTop||document.body.scrollTop;
// oDiv.style.top = (document.documentElement.clientHeight-oDiv.offsetHeight)/2+scrollTop+'px';
//可视区域的高度减掉物体高度再加上向上滚动的高度
starMove(parseInt((document.documentElement.clientHeight-oDiv.offsetHeight)/2+scrollTop));
//除以2以后就一直抖,就用parseInt取整
};
var timer = null;
function starMove(iTarget){
var oDiv = document.getElementById('div');
clearInterval(timer);
timer = setInterval(function(){
var speed = (iTarget-oDiv.offsetTop)/4;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(oDiv.offsetTop==iTarget){
clearInterval(timer)
}else{
document.title = iTarget;
document.getElementById('btn').value=oDiv.offsetTop;
oDiv.style.top = oDiv.offsetTop+speed+'px';
}
},30)
} </script>
</head> <body>
<div class="div" id="div"></div>
<input type="text" value="" id="btn" style="top: 0;
right: 0;
position: fixed;"/>
</body> </html>
课程链接:智能社的开发教程:https://ke.qq.com/webcourse/index.html#course_id=152997&term_id=100174752&taid=766913655494053&vid=v14127nxshc
JS-缓冲运动-对联型悬浮框的更多相关文章
- JS缓冲运动案例:右侧居中悬浮窗
JS缓冲运动案例:右侧居中悬浮窗 <!DOCTYPE html> <html lang="zh-CN"> <head> <meta cha ...
- JS缓冲运动案例:右下角悬浮窗
JS缓冲运动案例:右下角悬浮窗 红色区块模拟页面的右下角浮窗,在页面进行滚动时,浮窗做缓冲运动,最终在页面右下角停留. <!DOCTYPE html> <html lang=&quo ...
- JS-缓冲运动:菜单栏型悬浮框
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- js缓冲运动
缓冲运动 现象:逐渐变慢,最后停止 原理:距离越远,速度越大 速度的计算方式: 1,速度由距离决定 2,速度=(目标值-当前值)/缩放系数 说明:速度为正负数时,也决定了物体移动的方向 示例:div缓 ...
- JS缓冲运动案例
点击"向右"按钮,红色的#red区块开始向右缓冲运动,抵达到黑色竖线位置自动停止,再次点击"向右"#red区块也不会再运动.点击"向左"按钮 ...
- [Js]缓冲运动
一.运动框架 1.在开始运动时,关闭已有定时器(否则会不断有新的定时器执行) 2.把运动和停止隔开(if/else) 二.缓冲运动 逐渐变慢,最后停止(距离越远速度越大) 速度=(目标值-当前值)/缩 ...
- (40)JS运动之右下角悬浮框
<!DOCTYPE HTML> <!-- --> <html> <head> <meta charset="utf-8"> ...
- JS 缓冲运动 带运动的留言本 小案例
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
- JavaScript侧边悬浮框
<script> window.onscroll=function(){ var oDiv=document.getElementById('div1'); var scrollTop=d ...
随机推荐
- openwrt使用list
openwrt中用到双向无头链表,实际应用时应在外部定义实体链表头,后续可直接应用链表函数(宏定义已将链表头排除在外): static struct list_head timeouts = LIST ...
- EMC检测标准
- git不能上传空目录和设备文件
git不能上传空目录和设备文件:目录和设备文件不能完成校验. 使用命令校验: sha1sum console
- u-boot源码分析
Uboot源码分析 源码以u-boot-1.3.4为基准,主芯片采用at91sam9260,主要介绍uboot执行流程. uboot官网:http://www.denx.de/wiki/U-Boot/ ...
- jquery 自动完成 Autocomplete插件汇总
1. jQuery Autocomplete Mod jQuery Autcomplete插件.能够限制下拉菜单显示的结果数. 主页:http://www.pengoworks.com/worksho ...
- Charles安装包及破解包下载地址
Charles安装包及破解包下载地址 http://xclient.info/s/charles.html?_=baf317d2a9932afca9b32c327f8a34c9
- [mysql] 关联查询sql记录
//查询账单关联订单 select o.id as id, o.order_no as orderNo, o.case_no as caseNo, o.send_time as sendTime, o ...
- 关于Cocos2d-x中打包图集和使用方法
准备的过程 1.打开TextruePacker软件 2.把游戏中要使用的图片拖到TextruePacker里面,TextruePacker会自动帮我们排序,让所有小图变成一个大图 3.点击Publis ...
- Android ListView 笔记
ListView以列表的形式展示数据内容. 布局文件如下所示,添加一个ListView. activity_main.xml <?xml version="1.0" enco ...
- peek函数的用法
#include <iostream> /* run this program using the console pauser or add your own getch, system ...