Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. (function($) {
  2.  
  3. "use strict";
  4.  
  5.  
  6.  
  7.  
  8. var configureSlideshow = function() {
  9.  
  10. //scrollpane parts
  11. var scrollPane = $(this).find( ".scroll-pane" ),
  12. scrollContent = $(this).find( ".scroll-content" ),
  13. scrollbar = $(this).find( ".scroll-bar" );
  14.  
  15. //build slider
  16. scrollbar.slider({
  17. slide: function( event, ui ) {
  18. var margin = 0;
  19. if ( scrollContent.width() > scrollPane.width() ) {
  20. margin = Math.round(
  21. ui.value / 100 * ( scrollPane.width() - scrollContent.width() )
  22. );
  23. }
  24.  
  25. scrollContent.css( "margin-left", margin + "px" );
  26. }
  27. });
  28.  
  29. //append icon to handle
  30. var handleHelper = scrollbar.find( ".ui-slider-handle" )
  31. .mousedown(function() {
  32. scrollbar.width( handleHelper.width() );
  33. })
  34. .mouseup(function() {
  35. scrollbar.width( "100%" );
  36. })
  37. .append( "<span class='ui-icon ui-icon-grip-dotted-vertical'></span>" )
  38. .wrap( "<div class='ui-handle-helper-parent'></div>" ).parent();
  39.  
  40. //change overflow to hidden now that slider handles the scrolling
  41. scrollPane.css( "overflow", "hidden" );
  42.  
  43. //change handle position on window resize
  44. $( window ).resize(function() {
  45. resetValue(scrollContent, scrollPane, scrollbar);
  46. sizeScrollbar(scrollContent, scrollPane, scrollbar, handleHelper);
  47. reflowContent(scrollContent, scrollPane, scrollbar);
  48. });
  49.  
  50. //init scrollbar size
  51. setTimeout( function() {
  52. sizeScrollbar(scrollContent, scrollPane, scrollbar, handleHelper);
  53. }, 10 );//safari wants a timeout
  54.  
  55. }
  56.  
  57.  
  58.  
  59. //reset slider value based on scroll content position
  60. var resetValue = function(scrollContent, scrollPane, scrollbar) {
  61. var remainder = scrollPane.width() - scrollContent.width();
  62. var leftVal = scrollContent.css( "margin-left" ) === "auto" ? 0 :
  63. parseInt( scrollContent.css( "margin-left" ) );
  64. var percentage = Math.round( leftVal / remainder * 100 );
  65. scrollbar.slider( "value", percentage );
  66. }
  67.  
  68.  
  69.  
  70. //size scrollbar and handle proportionally to scroll distance
  71. var sizeScrollbar = function(scrollContent, scrollPane, scrollbar, handleHelper) {
  72. var remainder = scrollContent.width() - scrollPane.width();
  73. var proportion = remainder / scrollContent.width();
  74. var handleSize = scrollPane.width() - ( proportion * scrollPane.width() );
  75. scrollbar.find( ".ui-slider-handle" ).css({
  76. width: handleSize,
  77. "margin-left": -handleSize / 2
  78. });
  79. handleHelper.width( "" ).width( scrollbar.width() - handleSize );
  80. }
  81.  
  82.  
  83.  
  84. //if the slider is 100% and window gets larger, reveal content
  85. var reflowContent = function(scrollContent, scrollPane, scrollbar) {
  86. var showing = scrollContent.width() + parseInt( scrollContent.css( "margin-left" ), 10 );
  87. var gap = scrollPane.width() - showing;
  88. if ( gap > 0 ) {
  89. scrollContent.css( "margin-left", parseInt( scrollContent.css( "margin-left" ), 10 ) + gap );
  90. }
  91. }
  92.  
  93.  
  94.  
  95. $.fn.extend({configureSlideshow : configureSlideshow});
  96.  
  97.  
  98.  
  99. //init
  100. $(function() {
  101.  
  102. var slideshowSelectors = ['#slideshow1', '#slideshow2', '#slideshow3'],
  103. slideshowSelector,
  104. i;
  105.  
  106. for (i in slideshowSelectors) {
  107. slideshowSelector = slideshowSelectors[i];
  108. $(slideshowSelector).configureSlideshow();
  109. }
  110.  
  111. });
  112.  
  113. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement