首页 > 其他 > 详细

漂浮广告

时间:2015-10-26 15:07:28      阅读:207      评论:0      收藏:0      [点我收藏+]

<!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>

漂浮广告

原文:http://www.cnblogs.com/IsMyWay/p/4911069.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!