JavsScript实现网页左右侧淡入淡出效果
来源:互联网 发布:淘宝客服招聘网 编辑:程序博客网 时间:2024/05/16 15:46
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
body{overflow-X:hidden;}
#box1{
width: 150px;
height: 200px;
background-color: red;
position: absolute;
left: -150px;top: 100px;
}
#box1 span{
width: 20px;
height: 60px;
line-height: 20px;
display: inline-block;
position: absolute;right: -20px;top: 70px;
cursor: default;
}
#box2{
width: 150px;
height: 200px;
background-color: red;
position: absolute;
right: -150px;
top: 100px;
}
#box2 span{
width: 20px;
height: 60px;
line-height: 20px;
display: inline-block;
position: absolute;
left: -20px;
top: 70px;
cursor: default;
}
</style>
</head>
<body>
<div id="box1">
<span>分享到</span>
</div>
<div id="box2">
<span>分享到</span>
</div>
</body>
<script>
//左侧效果
(function(){
var oDiv = document.getElementById('box1');
var handler = null;
oDiv.onmouseover = function(){
startMove(0);
};
oDiv.onmouseout = function(){
startMove(-150);
};
function startMove(target){
clearInterval(handler);
var speed;
if(oDiv.offsetLeft>target){
speed = -5;
}else{
speed = 5;
};
handler = setInterval(function(){
if(oDiv.offsetLeft == target){
clearInterval(handler);
}else{
oDiv.style.left = oDiv.offsetLeft + speed + 'px';
};
},30);
};
})();
//右侧效果
(function(){
var oDiv = document.getElementById('box2');
var handler = null;
var bodyWidth = document.documentElement.clientWidth;//获取可视区域的宽度
oDiv.onmouseover = function(){
startMove(bodyWidth-150);
};
oDiv.onmouseout = function(){
startMove(bodyWidth);
};
function startMove(target){
clearInterval(handler);
var speed;
if(oDiv.offsetLeft > target){
speed = -5;
}else{
speed = 5;
};
handler = setInterval(function(){
if (oDiv.offsetLeft == target){
clearInterval(handler);
}else{
oDiv.style.left = oDiv.offsetLeft + speed +'px';
};
},30);
};
})();
</script>
</html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
body{overflow-X:hidden;}
#box1{
width: 150px;
height: 200px;
background-color: red;
position: absolute;
left: -150px;top: 100px;
}
#box1 span{
width: 20px;
height: 60px;
line-height: 20px;
display: inline-block;
position: absolute;right: -20px;top: 70px;
cursor: default;
}
#box2{
width: 150px;
height: 200px;
background-color: red;
position: absolute;
right: -150px;
top: 100px;
}
#box2 span{
width: 20px;
height: 60px;
line-height: 20px;
display: inline-block;
position: absolute;
left: -20px;
top: 70px;
cursor: default;
}
</style>
</head>
<body>
<div id="box1">
<span>分享到</span>
</div>
<div id="box2">
<span>分享到</span>
</div>
</body>
<script>
//左侧效果
(function(){
var oDiv = document.getElementById('box1');
var handler = null;
oDiv.onmouseover = function(){
startMove(0);
};
oDiv.onmouseout = function(){
startMove(-150);
};
function startMove(target){
clearInterval(handler);
var speed;
if(oDiv.offsetLeft>target){
speed = -5;
}else{
speed = 5;
};
handler = setInterval(function(){
if(oDiv.offsetLeft == target){
clearInterval(handler);
}else{
oDiv.style.left = oDiv.offsetLeft + speed + 'px';
};
},30);
};
})();
//右侧效果
(function(){
var oDiv = document.getElementById('box2');
var handler = null;
var bodyWidth = document.documentElement.clientWidth;//获取可视区域的宽度
oDiv.onmouseover = function(){
startMove(bodyWidth-150);
};
oDiv.onmouseout = function(){
startMove(bodyWidth);
};
function startMove(target){
clearInterval(handler);
var speed;
if(oDiv.offsetLeft > target){
speed = -5;
}else{
speed = 5;
};
handler = setInterval(function(){
if (oDiv.offsetLeft == target){
clearInterval(handler);
}else{
oDiv.style.left = oDiv.offsetLeft + speed +'px';
};
},30);
};
})();
</script>
</html>
0 0
- JavsScript实现网页左右侧淡入淡出效果
- 实现淡入淡出效果
- JavaScript实现淡入淡出效果
- WPF实现淡入淡出效果
- Axure实现淡入淡出效果
- Axure实现淡入淡出效果,axure实现淡入淡出
- J2me中实现淡入淡出效果
- Winform窗体淡入淡出效果实现
- 窗口淡入淡出效果的实现
- J2me中实现淡入淡出效果【收录】
- 窗口淡入淡出效果的实现
- 窗口淡入淡出效果的实现
- 窗口淡入淡出效果的实现
- J2me中实现淡入淡出效果
- C#实现窗体的淡入淡出效果
- 如何实现音频淡入淡出效果
- 如何实现音频淡入淡出效果
- C#窗体实现淡入淡出效果
- 循环对整数的位数进行统计
- poj 3468 A Simple Problem with Integers
- Git for Windows 安装和基本设置
- 使用ltp时,发现有些词没有切开,比如“信用卡拼音”
- part-14 轨至轨输入—TI的领先技术
- JavsScript实现网页左右侧淡入淡出效果
- CRC校验和原理(附源程序)
- java.lang.ClassNotFoundException: org.apache.poi.POIXMLTypeLoader
- 2012年第三届蓝桥杯C/C++程序设计本科B组决赛 DNA比对
- 常量指针和指针常量巧妙记忆方法
- java中关键字volatile的作用
- part-15 开环增益Avol
- asp.net 命令行工具初步了解
- 上古神器sed命令(下)