漂浮广告

<!DOCTYPE html>
<html lang="en">
<head>
 <title>Verlet Shapes</title>
 <meta charset="UTF-8" />
    <script type="text/javascript" src="jquery-1.11.3.min.js"></script>
<style type="text/css">
*{
 margin:auto 0px;
 padding:0px;
 }
#move{
 position:relative;
 }
</style> 
</head>
<body>
 <img src="123.jpg" style="width:200px;height:200px;" id="move">
 
 
 <script type="text/javascript">

 
 window.onload = function() {
  var longx = 10;
  var longy = 10;
  function imgmove(){
      var top = $("#move").offset().top;//获取当前元素距顶部距离
   var left = $("#move").offset().left;//获取当前元素距左侧距离
   //console.log(top);
   //console.log(left);
   if(top>=$(window).height()-200||top<0){//判断元素是否移动超出高度范围
     longx =-longx;
    }
    if(left>$(window).width()-200||left<0){//判断元素是否移动超出宽度范围
     longy =-longy;
     }
     top +=longx;
     left +=longy;
  //console.log(longx);
  $("#move").css({"top":top,"left":left});  
  
   }
 var time1 = setInterval(imgmove,20);
  $("#move").mouseover(function(){
     clearInterval(time1);
   }).mouseout(function(){
    time1 = setInterval(imgmove,20);
    })
 }
 
 </script>
 
</body>

posted on 2015-10-26 14:12  随风丶飘零  阅读(171)  评论(0编辑  收藏  举报