A floating box based on jquery (better scalability) _jquery

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

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title></title>
<style type= "Text/css" >
Body
{
height:2000px;
}
. float_mx{
Background: #CCC;
width:100px;
height:100px;
Display:none;
}
</style>
<body>
<div class= "Float_mx" >
Add content here
</div>
<script src= "Http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type= "Text/javascript" ></ Script>
<script type= "Text/javascript" >
(function ($) {
$.fn.scrollbox = function (options) {
var defaultoptions = {
speed:0.1,//acceleration
Time:16,//mobile speed
top:200,//default Top
Align: ' right ',//floating position, optional left
mix:0//Margin
};
var options = $.extend (defaultoptions, Options);
This.each (function () {
var obj = $ (this);
Init ();
function init () {
Obj.css (' Display ', ' block ');
Obj.css (' position ', ' absolute ');
Obj.css (Options.align, Options.mix);
Obj.css (' Top ', options.top+ ' px ');
Obj.css (' Z-index ', ' 99 ');
Move ();
}
function back () {
Acceleration = options.speed;
Time = Options.time;
var x1 = 0;
var y1 = 0;
var x2 = 0;
var y2 = 0;
if (document.documentelement) {
X1 = Document.documentElement.scrollLeft | | 0;
Y1 = Document.documentElement.scrollTop | | 0;
}
if (document.body) {
x2 = Document.body.scrollLeft | | 0;
y2 = Document.body.scrollTop | | 0;
}
var x = Math.max (x1, x2);
var y = Math.max (y1, y2);
var speed = acceleration;
return {
L:x,
T:y,
S:speed
};
};

function Move () {
var tip = obj;
var old = Options.top;
var pos = back (). t;
pos = pos-$ (TIP). Coordinate (). Y + options.top;
pos = $ (TIP). Coordinate (). Y + pos/10;
if (Pos < options.top) {
pos = options.top;
}
if (pos!= old) {
Tip.css (' top ', pos + "px");
}
Old = pos;
Window.settimeout (function () {move ();}, Options.time);
};
});
};
$.fn. coordinate = function () {
var E = $ (this) [0];
var C = e.offsettop;
var B = E.offsetleft;
var A = e.offsetwidth;
var D = e.offsetheight;
while (E = e.offsetparent) {
C + + e.offsettop;
B + + E.offsetleft;
}
return {
X:B,
Y:C,
W:a,
H:d
};
};
}) (JQuery);
$ ('. Float_mx '). Scrollbox ();
</script>
</body>

The following section of the agent into a separate JS file, the code in the CSS code can be deleted, display set to None, is to avoid the page does not finish loading, display incorrect questions.
Copy Code code as follows:

(function ($) {
$.fn.scrollbox = function (options) {
var defaultoptions = {
speed:0.1,//acceleration
Time:16,//mobile speed
top:200,//default Top
Align: ' right ',//floating position, optional left
mix:0//Margin
};
var options = $.extend (defaultoptions, Options);
This.each (function () {
var obj = $ (this);
Init ();
function init () {
Obj.css (' Display ', ' block ');
Obj.css (' position ', ' absolute ');
Obj.css (Options.align, Options.mix);
Obj.css (' Top ', options.top+ ' px ');
Obj.css (' Z-index ', ' 99 ');
Move ();
}
function back () {
Acceleration = options.speed;
Time = Options.time;
var x1 = 0;
var y1 = 0;
var x2 = 0;
var y2 = 0;
if (document.documentelement) {
X1 = Document.documentElement.scrollLeft | | 0;
Y1 = Document.documentElement.scrollTop | | 0;
}
if (document.body) {
x2 = Document.body.scrollLeft | | 0;
y2 = Document.body.scrollTop | | 0;
}
var x = Math.max (x1, x2);
var y = Math.max (y1, y2);
var speed = acceleration;
return {
L:x,
T:y,
S:speed
};
};

function Move () {
var tip = obj;
var old = Options.top;
var pos = back (). t;
pos = pos-$ (TIP). Coordinate (). Y + options.top;
pos = $ (TIP). Coordinate (). Y + pos/10;
if (Pos < options.top) {
pos = options.top;
}
if (pos!= old) {
Tip.css (' top ', pos + "px");
}
Old = pos;
Window.settimeout (function () {move ();}, Options.time);
};
});
};
$.fn. coordinate = function () {
var E = $ (this) [0];
var C = e.offsettop;
var B = E.offsetleft;
var A = e.offsetwidth;
var D = e.offsetheight;
while (E = e.offsetparent) {
C + + e.offsettop;
B + + E.offsetleft;
}
return {
X:B,
Y:C,
W:a,
H:d
};
};
}) (JQuery);

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.