Small plugins that slide with forms sticky source code _javascript Tips

Source: Internet
Author: User

Copy Code code as follows:

$.fn.stickyfloat = function (options, Lockbottom) {
var $obj = this;
var parentpaddingtop = parseint ($obj. Parent (). CSS (' padding-top '));
var startoffset = $obj. Parent (). Offset (). Top;
var opts = $.extend ({startoffset:startoffset, offsety:parentpaddingtop, duration:200, lockbottom:true }, Options);

$obj. css ({position: ' absolute '});

if (Opts.lockbottom) {
var Bottompos = $obj. Parent (). Height ()-$obj. Height () + parentpaddingtop;
if (Bottompos < 0)
Bottompos = 0;
}

$ (window). Scroll (function () {
$obj. Stop ();

var Paststartoffset = $ (document). ScrollTop () > Opts.startoffset;
var objfartherthantoppos = $obj. Offset (). Top > Startoffset;
var Objbiggerthanwindow = $obj. Outerheight () < $ (window). Height ();

if ((Paststartoffset | | objfartherthantoppos) && objbiggerthanwindow) {
var Newpos = ($ (document). ScrollTop ()-startoffset + opts.offsety);
if (Newpos > Bottompos)
Newpos = Bottompos;
if ($ (document). ScrollTop () < Opts.startoffset)
Newpos = Parentpaddingtop;

$obj. Animate ({Top:newpos}, opts.duration);
}
});
};


The use of the method is simple: simply introduce the plugin into the page and invoke it with the selector:
Copy Code code as follows:

$ (' #menu15 '). Stickyfloat ({duration:500});
$ (' #menu14 '). Stickyfloat ({duration:500});
$ (' #menu13 '). Stickyfloat ({duration:500});
$ (' #menu12 '). Stickyfloat ({duration:500});

The duration parameter at the back indicates the speed of the slide, the larger the slower.

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.