Advertisement
sastranababan

Untitled

Dec 12th, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. <script>
  2. (function () {
  3. var docElem = window.document.documentElement,
  4. didScroll, scrollPosition;
  5.  
  6. // trick to prevent scrolling when opening/closing button
  7. function noScrollFn() {
  8. window.scrollTo(scrollPosition ? scrollPosition.x : 0, scrollPosition ? scrollPosition.y : 0);
  9. }
  10.  
  11. function noScroll() {
  12. window.removeEventListener('scroll', scrollHandler);
  13. window.addEventListener('scroll', noScrollFn);
  14. }
  15.  
  16. function scrollFn() {
  17. window.addEventListener('scroll', scrollHandler);
  18. }
  19.  
  20. function canScroll() {
  21. window.removeEventListener('scroll', noScrollFn);
  22. scrollFn();
  23. }
  24.  
  25. function scrollHandler() {
  26. if (!didScroll) {
  27. didScroll = true;
  28. setTimeout(function () {
  29. scrollPage();
  30. }, 60);
  31. }
  32. };
  33.  
  34. function scrollPage() {
  35. scrollPosition = {
  36. x: window.pageXOffset || docElem.scrollLeft,
  37. y: window.pageYOffset || docElem.scrollTop
  38. };
  39. didScroll = false;
  40. };
  41.  
  42. scrollFn();
  43.  
  44. [].slice.call(document.querySelectorAll('.morph-button')).forEach(function (bttn) {
  45. new UIMorphingButton(bttn, {
  46. closeEl: '.icon-close',
  47. onBeforeOpen: function () {
  48. // don't allow to scroll
  49. noScroll();
  50. },
  51. onAfterOpen: function () {
  52. // can scroll again
  53. canScroll();
  54. },
  55. onBeforeClose: function () {
  56. // don't allow to scroll
  57. noScroll();
  58. },
  59. onAfterClose: function () {
  60. // can scroll again
  61. canScroll();
  62. }
  63. });
  64. });
  65.  
  66. // for demo purposes only
  67. [].slice.call(document.querySelectorAll('form button')).forEach(function (bttn) {
  68. bttn.addEventListener('click', function (ev) {
  69. ev.preventDefault();
  70. });
  71. });
  72. })();
  73. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement