Guest User

Untitled

a guest
May 26th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. (function($) {
  2. // This is a wrapper for $.load but scrolls to the position afterward
  3. $.fn.jqlws = function () {
  4.  
  5. if (this.length === 0) {
  6. return this;
  7. }
  8.  
  9. var args = arguments,
  10. url = args[0],
  11. callback = args[args.length - 1];
  12. // scrollTo = a jQuery wrapped object of the second part of the url
  13.  
  14. return this.each(function(i, elem) {
  15.  
  16. //If they supplied a callback - create a new function that will wrap the old one
  17. if (typeof callback === "function") {
  18. args[args.length - 1] = function() {
  19. var myOffset, scrollTo = $(url.substring(url.indexOf('#')));
  20. // call the original callback provided
  21. callback();
  22. // scroll afterwards
  23. if (scrollTo.length) {
  24. // If scroll plugin is loaded use it
  25. if ($.fn.scrollTo !== undefined) {
  26. $(elem).scrollTo(scrollTo);
  27. } else {
  28. myOffset = scrollTo.offset();
  29. window.scrollTo(myOffset.left, myOffset.top);
  30. }
  31. }
  32. }
  33. }
  34.  
  35. $(elem).load.apply($(elem), args);
  36.  
  37. });
  38.  
  39. }
  40. })(jQuery);
Add Comment
Please, Sign In to add comment