jQuery实现漂浮效果(网站提示)

首页看下效果

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="js/jquery-1.12.3.js" ></script>
<title>漂浮</title>
  <body style="min-width:1200px;">
     <DIV onmouseover="pause_resume()" onmouseout="pause_resume()" id=imgdiv style="Z-INDEX: 10000;  WIDTH: 200px; POSITION: absolute;  HEIGHT: 100px;
     visibility: visible;"><a href="/" target="_blank"><img src="fl-banner.jpg" width="200" height="100" border="0"></a></DIV>
    <div align="center">
      <p>
        <SCRIPT>
        var xPos = 0;
    	  var yPos = 0; 
   		  var step = 1;
    		var delay = 30; 
    		var height = 0;
    		var Hoffset = 0;
    		var Woffset = 0;
		    var yon = 0;
		    var xon = 0;
		    var pause = true;
		    var interval;
		    imgdiv.style.top = yPos;
    		function changePos() {
        width =  $(document.body).width();
        //width = document.body.clientWidth;
        height = $(window).height();
        //height = document.body.clientHeight;
        Hoffset = imgdiv.offsetHeight;
        Woffset = imgdiv.offsetWidth;
 				//console.log(yPos , document.body.scrollTop);
        //imgdiv.style.left = xPos + document.body.scrollLeft;
        //imgdiv.style.top = yPos + document.body.scrollTop;
        $("#imgdiv").css({"top":yPos ,"left":xPos});
        if (yon) 
            {yPos = yPos + step;}
        else 
            {yPos = yPos - step;}
        if (yPos < 0) 
            {yon = 1;yPos = 0;}
        if (yPos >= (height - Hoffset)) 
            {yon = 0;yPos = (height - Hoffset);}
        if (xon) 
            {xPos = xPos + step;}
        else 
            {xPos = xPos - step;}
        if (xPos < 0) 
            {xon = 1;xPos = 0;}
        if (xPos >= (width - Woffset)) 
            {xon = 0;xPos = (width - Woffset);   }
        }
        
        function start(){
            imgdiv.visibility = "visible";
            interval = setInterval('changePos()', delay);
        }
        function pause_resume() {
            if(pause) {
                clearInterval(interval);
                pause = false;
            }else{
                interval = setInterval('changePos()',delay);
                pause = true; 
            }
        }
        start();
        </SCRIPT>
      </p>
    </div>
 </body>
</html>

 

©️2020 CSDN 皮肤主题: 像素格子 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值