js源码--层动态变化
来源:互联网 发布:木工建模软件 编辑:程序博客网 时间:2024/05/17 01:12
<html>
<head>
<style type="text/css">
body {
height:100%;
}
#window, #window1 {
z-index:99;
position:absolute;
height:100px;
width:100px;
background-color:#CCCCCC;
}
#window1 {
z-index:100;
background-color:#00FF00;
}
#show {
height:2000px;
width:1px;
}
</style>
<script type="text/javascript">
var scrollGS = {
move : function (o) {
if (document.getElementById(o.id)) {
var left = document.body.scrollLeft - o.oscrollLeft;
var top = document.body.scrollTop - o.oscrollTop;
/*
滑动特效,暂时无做。。。
var leftFH = left / Math.abs(left);
var topFH = top / Math.abs(top);
*/
o.style.left = o.offsetLeft + left;
+ document.body.clientWidth - o.oclientWidth + "px";
o.style.top = o.offsetTop + top;
+ document.body.clientHeight - o.oclientHeight + "px";
o.oscrollLeft = document.body.scrollLeft;
o.oscrollTop = document.body.scrollTop;
o.oclientWidth = document.body.clientWidth;
o.oclientHeight = document.body.clientHeight;
window.status = o.style.top;
window.timeout(scrollGS.move, 50, o);
}
},
closemove : function (o) {
if (o.offsetTop - o.oscrollTop - document.body.clientHeight < 0) {
o.style.top = o.offsetTop + 1 + "px";
window.timeout(scrollGS.closemove, 10, o);
} else {
window.status = "已经移除.."
document.body.removeChild(o);
}
},
add : function (w) {
w.oscrollLeft = document.body.scrollLeft;
w.oscrollTop = document.body.scrollTop;
w.oclientWidth = document.body.clientWidth;
w.oclientHeight = document.body.clientHeight;
w.style.left = w.oscrollLeft + document.body.clientWidth - w.offsetWidth;
w.style.top = w.oscrollTop + document.body.clientHeight - w.offsetHeight;
w.onmousedown = function () {
scrollGS.closemove(w);
};
scrollGS.move(w);
}
};
(function () {
window.timeout = function (a, b) {
var fun = a;
if ("function" == typeof a) {
var arg = Array.prototype.slice.call(arguments, 2);
fun = function () {
a.apply(null, arg);
}
}
window.setTimeout(fun, b);
}
})();
window.onload = function () {
scrollGS.add(document.getElementById("window"));
scrollGS.add(document.getElementById("window1"));
}
</script>
</head>
<body>
<div id="window"></div>
<div id="window1"></div>
<div id="show"></div>
</body>
</html>
<head>
<style type="text/css">
body {
height:100%;
}
#window, #window1 {
z-index:99;
position:absolute;
height:100px;
width:100px;
background-color:#CCCCCC;
}
#window1 {
z-index:100;
background-color:#00FF00;
}
#show {
height:2000px;
width:1px;
}
</style>
<script type="text/javascript">
var scrollGS = {
move : function (o) {
if (document.getElementById(o.id)) {
var left = document.body.scrollLeft - o.oscrollLeft;
var top = document.body.scrollTop - o.oscrollTop;
/*
滑动特效,暂时无做。。。
var leftFH = left / Math.abs(left);
var topFH = top / Math.abs(top);
*/
o.style.left = o.offsetLeft + left;
+ document.body.clientWidth - o.oclientWidth + "px";
o.style.top = o.offsetTop + top;
+ document.body.clientHeight - o.oclientHeight + "px";
o.oscrollLeft = document.body.scrollLeft;
o.oscrollTop = document.body.scrollTop;
o.oclientWidth = document.body.clientWidth;
o.oclientHeight = document.body.clientHeight;
window.status = o.style.top;
window.timeout(scrollGS.move, 50, o);
}
},
closemove : function (o) {
if (o.offsetTop - o.oscrollTop - document.body.clientHeight < 0) {
o.style.top = o.offsetTop + 1 + "px";
window.timeout(scrollGS.closemove, 10, o);
} else {
window.status = "已经移除.."
document.body.removeChild(o);
}
},
add : function (w) {
w.oscrollLeft = document.body.scrollLeft;
w.oscrollTop = document.body.scrollTop;
w.oclientWidth = document.body.clientWidth;
w.oclientHeight = document.body.clientHeight;
w.style.left = w.oscrollLeft + document.body.clientWidth - w.offsetWidth;
w.style.top = w.oscrollTop + document.body.clientHeight - w.offsetHeight;
w.onmousedown = function () {
scrollGS.closemove(w);
};
scrollGS.move(w);
}
};
(function () {
window.timeout = function (a, b) {
var fun = a;
if ("function" == typeof a) {
var arg = Array.prototype.slice.call(arguments, 2);
fun = function () {
a.apply(null, arg);
}
}
window.setTimeout(fun, b);
}
})();
window.onload = function () {
scrollGS.add(document.getElementById("window"));
scrollGS.add(document.getElementById("window1"));
}
</script>
</head>
<body>
<div id="window"></div>
<div id="window1"></div>
<div id="show"></div>
</body>
</html>
今天偶然看到一个帖子,如果是我的写法会
<html>
<head>
<style type="text/css">
body {
height:100%;
}
#window, #window1 {
z-index:99;
position:absolute;
height:100px;
width:100px;
background-color:#CCCCCC;
}
#window1 {
z-index:100;
background-color:#00FF00;
}
#show {
height:2000px;
width:1px;
}
</style>
<script type="text/javascript">
window.onload = function () {
add(document.getElementById("window"));
add(document.getElementById("window1"));
}
function add(w) {
w.oscrollLeft = document.body.scrollLeft;
w.oscrollTop = document.body.scrollTop;
w.oclientWidth = document.body.clientWidth;
w.oclientHeight = document.body.clientHeight;
w.style.left = w.oscrollLeft + document.body.clientWidth - w.offsetWidth;
w.style.top = w.oscrollTop + document.body.clientHeight - w.offsetHeight;
w.onmousedown = function () {
closemove(w);
}
move(w);
}
function closemove(o) {
if (o.offsetTop - o.oscrollTop - document.body.clientHeight < 0) {
o.style.top = o.offsetTop + 1 + "px";
window.timeout(closemove, 10, o);
}
else {
window.status = "已经移除.."
document.body.removeChild(o);
}
}
function move (o) {
if (document.getElementById(o.id)) {
var left = document.body.scrollLeft - o.oscrollLeft;
var top = document.body.scrollTop - o.oscrollTop;
/*
滑动特效,暂时无做。。。
var leftFH = left / Math.abs(left);
var topFH = top / Math.abs(top);
*/
o.style.left = o.offsetLeft + left;
+ document.body.clientWidth - o.oclientWidth + "px";
o.style.top = o.offsetTop + top;
+ document.body.clientHeight - o.oclientHeight + "px";
o.oscrollLeft = document.body.scrollLeft;
o.oscrollTop = document.body.scrollTop;
o.oclientWidth = document.body.clientWidth;
o.oclientHeight = document.body.clientHeight;
window.status = o.style.top;
window.timeout(move, 50, o);
}
}
(function () {
window.timeout = function (a, b) {
var fun = a;
if ("function" == typeof a) {
var arg = Array.prototype.slice.call(arguments, 2);
fun = function () {
a.apply(null, arg);
}
}
window.setTimeout(fun, b);
}
})();
</script>
</head>
<body>
<div id="window"></div>
<div id="window1"></div>
<div id="show"></div>
</body>
</html>
<head>
<style type="text/css">
body {
height:100%;
}
#window, #window1 {
z-index:99;
position:absolute;
height:100px;
width:100px;
background-color:#CCCCCC;
}
#window1 {
z-index:100;
background-color:#00FF00;
}
#show {
height:2000px;
width:1px;
}
</style>
<script type="text/javascript">
window.onload = function () {
add(document.getElementById("window"));
add(document.getElementById("window1"));
}
function add(w) {
w.oscrollLeft = document.body.scrollLeft;
w.oscrollTop = document.body.scrollTop;
w.oclientWidth = document.body.clientWidth;
w.oclientHeight = document.body.clientHeight;
w.style.left = w.oscrollLeft + document.body.clientWidth - w.offsetWidth;
w.style.top = w.oscrollTop + document.body.clientHeight - w.offsetHeight;
w.onmousedown = function () {
closemove(w);
}
move(w);
}
function closemove(o) {
if (o.offsetTop - o.oscrollTop - document.body.clientHeight < 0) {
o.style.top = o.offsetTop + 1 + "px";
window.timeout(closemove, 10, o);
}
else {
window.status = "已经移除.."
document.body.removeChild(o);
}
}
function move (o) {
if (document.getElementById(o.id)) {
var left = document.body.scrollLeft - o.oscrollLeft;
var top = document.body.scrollTop - o.oscrollTop;
/*
滑动特效,暂时无做。。。
var leftFH = left / Math.abs(left);
var topFH = top / Math.abs(top);
*/
o.style.left = o.offsetLeft + left;
+ document.body.clientWidth - o.oclientWidth + "px";
o.style.top = o.offsetTop + top;
+ document.body.clientHeight - o.oclientHeight + "px";
o.oscrollLeft = document.body.scrollLeft;
o.oscrollTop = document.body.scrollTop;
o.oclientWidth = document.body.clientWidth;
o.oclientHeight = document.body.clientHeight;
window.status = o.style.top;
window.timeout(move, 50, o);
}
}
(function () {
window.timeout = function (a, b) {
var fun = a;
if ("function" == typeof a) {
var arg = Array.prototype.slice.call(arguments, 2);
fun = function () {
a.apply(null, arg);
}
}
window.setTimeout(fun, b);
}
})();
</script>
</head>
<body>
<div id="window"></div>
<div id="window1"></div>
<div id="show"></div>
</body>
</html>
虽然差不多但是感觉需时越兔的结果性更好一些,确实是值得学习,非常棒的事例
- js源码--层动态变化
- js源码--动态层
- js源码--动态层
- js实现页面时间动态变化
- JS访问动态变化的对象
- js动态效果拖动层排序
- Js代码动态移动层-拖动浮层并关闭
- js实现随滚动条滚动div位置动态变化
- vue动态数据绑定3--深层次数据变化逐层往上传播
- js实现层关闭/文本框2的值随文本框1内数字变化
- 【源码】一个动态日历的JS
- js浮动弹出层定位的问题,有源码
- js实现根据下拉列表动态改变其他层
- arcgis for js动态加载图层方法
- Grid数据源动态变化
- 图片的动态变化
- ColorStateList 动态颜色变化
- 实现数字动态变化
- Linux 下的一个全新的性能测量和调式诊断工具 Systemtap, 第 3 部分: Systemtap
- eclipse+cdt+minGW配置
- 如何查看oracle sql执行计划
- 我的美国行 .. NASA (Space center)
- 三月份实习总结
- js源码--层动态变化
- 面向对象设计模式开题报告
- Spring.Net&NHibernate 学习 3
- jbpm+tomcat+mysql配置指南
- 开始好好学Java
- 浅谈“三层结构”原理与用意
- ASP.Net中防止页面刷新重复提交的几种方法
- Hashtable和HashMap类的区别(转载自-http://hi.baidu.com/danghj/blog/item/635c862f15949c381f3089a4.html)
- 下拉日期控件