CapacityFixed is a jquery-based positioning box similar to Sina Weibo's new message prompts.

Source: Internet
Author: User
In the company's project requirements, there is a positioning box similar to the Sina Weibo message prompts. For more information, see. :

When the browser is rolling, when the browser needs to float the layer to remove the browser interface view area, modify its position attribute so that it can be displayed along the top edge of the window, position: fixed, you can perform smooth and fixed positioning on the floating layer in IE7 + and other browsers. Because IE6's predecessors do not support the fixed attribute, use the position: absolute attribute instead to recalculate the top value.
The Code is as follows:
HTML code:

The Code is as follows:



1 New private message, view private message


View 10 new messages


108 new fans, view fans


Close



CSS code:

The Code is as follows:


. Float {width: 200px; padding: 5px 10px; border: 1px solid # ffecb0; font-size: 12px; background-color: # fffee0;-moz-box-shadow: 1px 1px 2px rgba (0, 0 ,. 2);-webkit-box-shadow: 1px 1px 2px rgba (0, 0 ,. 2); box-shadow: 1px 1px 2px rgba (0, 0 ,. 2); position: absolute;-moz-border-radius: 5px;-webkit-border-radius: 5px; border-radius: 5px ;}
. Float. close-ico {position: absolute; top: 5px; right: 5px; display: block; width: 16px; height: 16px; background-image: url (img/close-ico.png ); text-indent:-900px; overflow: hidden ;}
. Float. close-ico: hover {background-position: 0-16px ;}
. Float p {line-height: 22px}


JS Code:

The Code is as follows:


/**
* @ Author Yuen Wharf
* Similar to the positioning box of Sina Weibo message prompts
* More
*/
(Function ($ ){
$. Fn. capacityFixed = function (options ){
Var opts = $. extend ({}, $. fn. capacityFixed. deflunt, options );

Var FixedFun = function (element ){
Var top = opts. top;
Var right = ($ (window). width ()-opts. pageWidth)/2 + opts. right;
Element.css ({
"Right": right,
"Top": top
});
$ (Window). resize (function (){
Var right = ($ (window). width ()-opts. pageWidth)/2 + opts. right;
Element.css ({
"Right": right
});
});
$ (Window). scroll (function (){
Var scrolls = $ (this). scrollTop ();
If (scrolls> top ){

If (window. XMLHttpRequest ){
Element.css ({
Position: "fixed ",
Top: 0
});
} Else {
Element.css ({
Top: scrolls
});
}
} Else {
Element.css ({
Position: "absolute ",
Top: top
});
}
});
Element. find (". close-ico"). click (function (event ){
Element. remove ();
Event. preventDefault ();
})
};
Return $ (this). each (function (){
FixedFun ($ (this ));
});
};
$. Fn. capacityFixed. deflunt = {
Right: 100, // locate the right side of the page relative to the page width
Top: 100,
PageWidth: 960
};
}) (JQuery );

Related Article

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.