码迷,mamicode.com
首页 > Web开发 > 详细

js 分享 运动框架

时间:2017-05-09 22:27:12      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:pre   val   ons   html   null   var   tar   line   logs   

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style>
#div1{
    width:100px;
    height:200px;
    background:red;
    position:absolute;
    left:-100px
    
}
#span1{
    width:20px;
    height:60px;
    background:blue;
    position:absolute;
    line-height:20px;
    top:70px;
    right:-20px;
}
</style>
<script>
window.onload=function(){
    var odiv=document.getElementById(div1);
    
    odiv.onmouseover=function(){
        onStart(0);
        }
        odiv.onmouseout=function(){
        onStart(-100);
        }
        
    }
    var timer=null;
function onStart(oTag){
        var odiv=document.getElementById(div1);
    clearInterval(timer);
    var speed=null;
    if(speed>oTag){
        speed=-10;
        }else{
            speed=10;
            }
    timer=setInterval(function (){
    
        if(odiv.offsetLeft==oTag){
            clearInterval(timer);
            }else{
                odiv.style.left=odiv.offsetLeft+speed+px;
                }
        },30)
    }
    
    
</script>
</head>

<body>
<div id="div1">
<span id="span1">分享到</span>
</div>
</body>
</html>

关于速度的小解释

分享框
left30 tag300 正
left600 tag30 负

js 分享 运动框架

标签:pre   val   ons   html   null   var   tar   line   logs   

原文地址:http://www.cnblogs.com/zwn-lucky7/p/6832962.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!