分享侧边栏——js代码
来源:互联网 发布:php curl 301跳转 编辑:程序博客网 时间:2024/06/03 19:04
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
*{margin: 0;padding: 0;}
#div1{position: relative;width: 150px;height: 150px;background: red; top: 50px; left: -150px; }
#sp{position: absolute; background: #ccc;top: 40px;right: -20px; width: 20px;height: 70px;}
</style>
<script>
// //第一种方法:
// window.onload=function(){
// var oDiv1=document.getElementById('div1');
// oDiv1.onmouseover=function()
// {
// startMove();
// };
// oDiv1.onmouseout=function(){
// startMove2();
// };
// }
// //设一个全局变量 timer=null;
// var timer=null;
// function startMove(){
// clearInterval(timer);
// var oDiv1=document.getElementById('div1');
// timer=setInterval(function(){
// if (oDiv1.offsetLeft==0){
// clearInterval(timer);
// }
// //若用style.left要加px;即使是0也要加px;否则不能识别 不会跑startMove函数。
// if (oDiv1.style.left==0+'px'){
// clearInterval(timer);
// }
// else{
// oDiv1.style.left=oDiv1.offsetLeft+10+'px';
// }
// },30)
// }
// function startMove2(){
// clearInterval(timer);
// var oDiv1=document.getElementById('div1');
// timer=setInterval(function(){
// if (oDiv1.offsetLeft==-150){
// clearInterval(timer);
// }
// else{
// oDiv1.style.left=oDiv1.offsetLeft-10+'px';
// }
// },30)
// }
//第二种方法:
// window.onload=function(){
// var oDiv=document.getElementById('div1');
// oDiv.onmouseover=function()
// {
// startMove(oDiv,0,10);
// };
// oDiv.onmouseout=function(){
// startMove(oDiv,-150,-10);
// };
// }
// //设一个全局变量 timer=null;
// var timer=null;
// function startMove(obj,iTarget,speed){
// clearInterval(timer);
// timer=setInterval(function(){
// if (obj.style.left==iTarget+'px'){
// clearInterval(timer);
// }
// else{
// obj.style.left=obj.offsetLeft+speed+'px';
// }
// },30)
// }
//第三种方法 只需要一个参数,使得函数调用越来越简单,但是这是在知道speed的情况下
window.onload=function(){
var oDiv=document.getElementById('div1');
oDiv.onmouseover=function()
{
startMove(0);
};
oDiv.onmouseout=function(){
startMove(-150);
};
}
//设一个全局变量 timer=null;
var timer=null;
function startMove(iTarget){
var oDiv=document.getElementById('div1');
clearInterval(timer);
timer=setInterval(function(){
var speed=0;
if(iTarget<oDiv.offsetLeft)
{
speed=-10;
}
else
{
speed=10;
}
if (oDiv.offsetLeft==iTarget)
{
clearInterval(timer);
}
else
{
oDiv.style.left=oDiv.offsetLeft+speed+'px';
document.title=speed;
}
},30)
}
</script>
</head>
<body>
<div id="div1">
<span id="sp">分享到</span>
</div>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
*{margin: 0;padding: 0;}
#div1{position: relative;width: 150px;height: 150px;background: red; top: 50px; left: -150px; }
#sp{position: absolute; background: #ccc;top: 40px;right: -20px; width: 20px;height: 70px;}
</style>
<script>
// //第一种方法:
// window.onload=function(){
// var oDiv1=document.getElementById('div1');
// oDiv1.onmouseover=function()
// {
// startMove();
// };
// oDiv1.onmouseout=function(){
// startMove2();
// };
// }
// //设一个全局变量 timer=null;
// var timer=null;
// function startMove(){
// clearInterval(timer);
// var oDiv1=document.getElementById('div1');
// timer=setInterval(function(){
// if (oDiv1.offsetLeft==0){
// clearInterval(timer);
// }
// //若用style.left要加px;即使是0也要加px;否则不能识别 不会跑startMove函数。
// if (oDiv1.style.left==0+'px'){
// clearInterval(timer);
// }
// else{
// oDiv1.style.left=oDiv1.offsetLeft+10+'px';
// }
// },30)
// }
// function startMove2(){
// clearInterval(timer);
// var oDiv1=document.getElementById('div1');
// timer=setInterval(function(){
// if (oDiv1.offsetLeft==-150){
// clearInterval(timer);
// }
// else{
// oDiv1.style.left=oDiv1.offsetLeft-10+'px';
// }
// },30)
// }
//第二种方法:
// window.onload=function(){
// var oDiv=document.getElementById('div1');
// oDiv.onmouseover=function()
// {
// startMove(oDiv,0,10);
// };
// oDiv.onmouseout=function(){
// startMove(oDiv,-150,-10);
// };
// }
// //设一个全局变量 timer=null;
// var timer=null;
// function startMove(obj,iTarget,speed){
// clearInterval(timer);
// timer=setInterval(function(){
// if (obj.style.left==iTarget+'px'){
// clearInterval(timer);
// }
// else{
// obj.style.left=obj.offsetLeft+speed+'px';
// }
// },30)
// }
//第三种方法 只需要一个参数,使得函数调用越来越简单,但是这是在知道speed的情况下
window.onload=function(){
var oDiv=document.getElementById('div1');
oDiv.onmouseover=function()
{
startMove(0);
};
oDiv.onmouseout=function(){
startMove(-150);
};
}
//设一个全局变量 timer=null;
var timer=null;
function startMove(iTarget){
var oDiv=document.getElementById('div1');
clearInterval(timer);
timer=setInterval(function(){
var speed=0;
if(iTarget<oDiv.offsetLeft)
{
speed=-10;
}
else
{
speed=10;
}
if (oDiv.offsetLeft==iTarget)
{
clearInterval(timer);
}
else
{
oDiv.style.left=oDiv.offsetLeft+speed+'px';
document.title=speed;
}
},30)
}
</script>
</head>
<body>
<div id="div1">
<span id="sp">分享到</span>
</div>
</body>
</html>
阅读全文
0 0
- 分享侧边栏——js代码
- js分享到侧边栏
- JS实现"分享到"侧边栏
- javascript——运动侧边分享
- 初探js特效魅力之“分享到”侧边栏
- JS运动框架之分享侧边栏动画
- 运动框架(js)—上下滑动的侧边栏
- js 侧边栏
- 侧边栏-css+js侧边栏运动
- Fragment使用—侧边栏
- js实现侧边栏效果
- 侧边栏天气预报代码设置
- JavaScript 运动之侧边分享栏
- 电脑精简桌面——侧边栏
- HTML——左侧边栏布局
- HTML——左右侧边栏布局
- Ionic基础——侧边栏ion-side-menus 以及ion-tap结合侧边栏详解
- JS固定侧边栏教程总结
- jsp中的作用域对象
- ubuntu 文件目录结构
- 什么是数字签名
- eMMC 启动过程
- 写在博客开通的第一天
- 分享侧边栏——js代码
- 格雷码
- 浅谈android的selector,背景选择器
- theano-xnor-net代码注释9 pylearn2/cifar10.py
- android开发之用户头像上传
- jsp 注册时同意协议才能点击注册按钮功能及样式控制 简单例子
- list转json字符串
- 编译通过testLogin
- 使用openvr开发Oculus时手柄按键的问题(不定期更新)