SoFunction
Updated on 2025-04-06

js right-hand floating layer effect implementation code (follow scrolling)

Implementation code 1.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
 <title>Untitled Document</title>
 <!--***********start*************-->

 <script type="text/javascript">
  //<![CDATA[ 
  var tips; var theTop = 200/*This is the default height, the larger the lower the */; var old = theTop;
  function initFloatTips() {
   tips = ('floatTips');
   moveTips();
  };
  function moveTips() {
   var tt = 50;
   if () {
    pos = 
   }
   else if ( && ) {
    pos = 
   }
   else if () {
    pos = ;
   }
   pos = pos -  + theTop;
   pos =  + pos / 10;
   if (pos < theTop) pos = theTop;
   if (pos != old) {
     = pos + "px";
    tt = 10;
   }
   old = pos;
   setTimeout(moveTips, tt);
  }
  //!]]> 
 </script>

 <style type="text/css">
  .floatTips
  {
   position: absolute;
   border: solid 1px #777;
   padding: 3px;
   top: 250px;
   right: 5px;
   width: 30px;
   height: 300px;
   background: #cccccc;
   color: white;
  }
  .showDiv
  {
   position: absolute;
   border: solid 1px #777;
   padding: 3px;
   top: 250px;
   right: 5px;
   width: 300px;
   height: 300px;
   background: #cccccc;
   color: white;
  }
 </style>
 <script type="text/javascript">
  function FunOnmouseUp() {
   var objFloatTips = $("floatTips");
   var objActivityContext = $("activityContext");
    = "showDiv";
    = "";
  }
  function FunMouseOut() {
   var objFloatTips = $("floatTips");
   var objActivityContext = $("activityContext");
    = "floatTips";
    = "none";
  }

  function $(objID) {
   return (objID);
  }
 </script>

</head>
<body onload="initFloatTips()">
 <div  onmouseover="FunOnmouseUp()" onmouseout="FunMouseOut()" class="floatTips">
  Latest Events
  <div  style="display: none">
   显示Latest Events
  </div>
 </div>
 <!--**********Finish***************-->
 <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#F7F7F7">
  <tr>
   <td height="2101">
   </td>
  </tr>
 </table>
</body>
</html>

If you have time, it will be beautify it slightly and add animation effects. It should be considered a good floating hidden layer.

Method 2.

1. Insert the following code into the <body></body> tag:

 &lt;div  style="position: absolute;top: 0px; border-right: activeborder 1px solid; border-top: activeborder 1px solid; border-left: activeborder 1px solid; border-bottom: activeborder 1px solid;"&gt;
  &amp;nbsp;Floating layer example:&lt;br /&gt;
  &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;a target="_blank" href="tencent://message/?uin=101535223&Site=https://&Menu=yes"><img border="0" src="/pa?p=1:101535223:3" alt="If you have something to say"></a> &lt;/div&gt; 

2. After inserting the following code into the </body> tag, set the values ​​of the four variables: MarginLeft, MarginTop, Width, and Heigth.

&lt;script language="javascript" type="text/javascript"&gt;
var MarginLeft = 30; //The distance of the floating layer to the right side of the browservar MarginTop = 50;  //The distance of the floating layer from the top of the browservar Width = 120;  //Floating layer widthvar Heigth= 45;  //Floating layer height
//Set the width and height of the floating layerfunction Set()
{
 ("FloatDIV"). = Width;
 ("FloatDIV"). = Heigth;
}

// Set the position of the floating layer in real timefunction Move()
{
 ("FloatDIV"). =  + MarginTop;
 ("FloatDIV"). =  - Width - MarginLeft;
 setTimeout("Move();",100);
}

Set();
Move();
&lt;/script&gt;