JS follow scroll bar scrolling floating code _javascript tips

Source: Internet
Author: User
Copy Code code as follows:

var str= "Customer service";
var objft=new floatt ("FloatMenu1", str,942,137,125,200,80,10);
Objft.floatrun ();


JS follows the scroll bar scroll floating
pobjname:html Element ID
ptext:html element content
Others see for themselves
function Floatt (pobjname,ptext,pstmnleft,pstmngap1,pstmngap2,pstmnbase,pstmnactivatespeed,pstmnscrollspeed)
{
var Floatmenu;
var stmnleft = Pstmnleft;
var stmnGAP1 = pstmnGAP1;
var stmnGAP2 = pstmnGAP2;
var stmnbase = pstmnbase;
var stmnactivatespeed = pstmnactivatespeed;
var stmnscrollspeed = pstmnscrollspeed;

This. Floatrun=function (Pobjname)
{
var newdiv=document.createelement ("div");
Newdiv.id=pobjname;
Newdiv.innerhtml=ptext;
newdiv.style.position= "Absolute";
Document.body.appendChild (NEWDIV);
Floatmenu=document.getelementbyid (Pobjname);
floatmenu.style.display== "";
FloatMenu.style.top = Document.documentElement.scrollTop + stmnbase+ "px";

FloatMenu.style.left = stmnleft+ "px";
Refreshstaticmenu ();
}

Refreshstaticmenu=function ()
{
var Stmnstartpoint,stmnendpoint,stmnrefreshtimer;

Stmnstartpoint = parseint (FloatMenu.style.top, 10);
Stmnendpoint = Document.documentElement.scrollTop + stmnGAP2;
if (Stmnendpoint < stmnGAP1) Stmnendpoint = stmnGAP1;

if (Stmnstartpoint!= stmnendpoint)
{
Stmnscrollamount = Math.ceil (Math.Abs (stmnendpoint-stmnstartpoint)/15);
FloatMenu.style.top = parseint (FloatMenu.style.top) + ((stmnendpoint<stmnstartpoint)?-stmnscrollamount: Stmnscrollamount) + "px";
Stmnrefreshtimer = Stmnscrollspeed;
}
Else
{
Stmnrefreshtimer = Stmnactivatespeed;
}
SetTimeout ("Refreshstaticmenu ();", Stmnrefreshtimer);
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.