Guest User

Untitled

a guest
May 27th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. var scroll = {
  2. // calculats width of all icons
  3. calculateWidth: function(outerWidth) {
  4. // default to outer width (includes margins)
  5. if(typeof(outerWidth) == 'undefined') {
  6. var outerWidth = true;
  7. }
  8. // EDIT THIS SECTION, HAVE THIS LOOK FOR OFFSET OF LAST CHILD OF DIV *figures out relative size*
  9. var $lastLi = $('#content > ul > li:last-child');
  10. if($lastLi.exists()) {
  11. var ulWidth = $lastLi[0].offsetLeft + $lastLi.outerWidth();
  12. if(outerWidth) {
  13. var ulPadding = fav4.scroller.padding * 2;
  14. return ulWidth + ulPadding;
  15. }
  16. return ulWidth;
  17. }
  18. },
  19. positionMenu: function() {
  20. var $menu = $('#content');
  21. var width = $(window).width();
  22. var ulWidth = fav4.scroll.calculateWidth();
  23. var iconWidth = fav4.iconWidth;
  24. // position menu in center if smaller than window width
  25. if(ulWidth < width) {
  26. $menu
  27. .removeClass('dynamic')
  28. .addClass('static')
  29. .css({
  30. width: ulWidth+'px',
  31. left: '50%',
  32. marginLeft: '-'+(ulWidth / 2)+'px'
  33. })
  34. ;
  35. }
  36. // remove styles if not
  37. else {
  38. $menu
  39. .removeClass('static')
  40. .addClass('dynamic')
  41. .removeAttr('style');
  42. }
  43. // position icons in center
  44. $menu.scrollLeft((ulWidth-width) / 2);
  45. },
  46. getRatios: function() {
  47. var $menu = $('#content');
  48. //Get menu width
  49. var menuWidth = $menu.width();
  50. var ulWidth = fav4.scroll.calculateWidth();
  51. var menuOffset = $menu.offset().left;
  52. var ratio = ((ulWidth - menuWidth) / menuWidth);
  53. var menuRatio = menuOffset * ratio;
  54. return { ratio: ratio, menuRatio: menuRatio };
  55. },
  56. bindEvents: function() {
  57. var $menu = $('#content');
  58. var ratios = fav4.scroll.getRatios();
  59. // handles position of menu on mousemove dom event
  60. $(window)
  61. .bind('resize.scroll', function() {
  62. $('#content').css('overflow', 'hidden');
  63. var ratios = fav4.scroll.getRatios();
  64. fav4.scroll.positionMenu();
  65. $menu
  66. .unbind('mousemove.scroll')
  67. .bind('mousemove.scroll', function(e){
  68. var x = e.pageX;
  69. if(!fav4.noScrollMode && x!= 0) {
  70. content.scrollLeft = (x * ratios.ratio) - ratios.menuRatio;
  71. }
  72. })
  73. ;
  74. $('#content').css('overflow', '');
  75. })
  76. ;
  77. $menu.bind('mousemove.scroll', function(e){
  78. var x = e.pageX;
  79. if(!fav4.noScrollMode && x!= 0) {
  80. var content = document.getElementById('content');
  81. content.scrollLeft = (x * ratios.ratio) - ratios.menuRatio;
  82. }
  83. });
  84. },
  85. unbindEvents: function() {
  86. var $menu = $('#content');
  87. $menu.unbind('mousemove.scroll');
  88. $(window).unbind('resize.scroll');
  89. }
  90. }
Add Comment
Please, Sign In to add comment