Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function($) {
- // This is a wrapper for $.load but scrolls to the position afterward
- $.fn.jqlws = function () {
- if (this.length === 0) {
- return this;
- }
- var args = arguments,
- url = args[0],
- callback = args[args.length - 1];
- // scrollTo = a jQuery wrapped object of the second part of the url
- return this.each(function(i, elem) {
- //If they supplied a callback - create a new function that will wrap the old one
- if (typeof callback === "function") {
- args[args.length - 1] = function() {
- var myOffset, scrollTo = $(url.substring(url.indexOf('#')));
- // call the original callback provided
- callback();
- // scroll afterwards
- if (scrollTo.length) {
- // If scroll plugin is loaded use it
- if ($.fn.scrollTo !== undefined) {
- $(elem).scrollTo(scrollTo);
- } else {
- myOffset = scrollTo.offset();
- window.scrollTo(myOffset.left, myOffset.top);
- }
- }
- }
- }
- $(elem).load.apply($(elem), args);
- });
- }
- })(jQuery);
Add Comment
Please, Sign In to add comment