Advertisement
Guest User

Untitled

a guest
May 1st, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. <div class="wrapper">
  2. <div class="screen" id="screen-1" data-video="vid/bird.mp4" data-autoslide="15000">
  3. <img src="img/bird.jpg" class="big-image" />
  4. <h1 class="video-title" style="color:#000">Image 1 </h1>
  5. </div>
  6. <div class="screen" id="screen-2" data-video="vid/satellite.mp4" data-autoslide="15000">
  7. <img src="img/satellite.jpg" class="big-image" />
  8. <h1 class="video-title" style="color:#000">Image 2 /h1>
  9. </div>
  10. <div class="screen" id="screen-3" data-video="vid/camera.mp4" data-autoslide="15000">
  11. <img src="img/camera.jpg" class="big-image" />
  12. <h1 class="video-title" style="color:#000">Image 3 </h1>
  13. </div>
  14. <div class="screen" id="screen-4" data-video="vid/spider.mp4" data-autoslide="15000">
  15. <img src="img/spider.jpg" class="big-image" />
  16. <h1 class="video-title" style="color:#000">Image 4 </h1>
  17. </div>
  18. <div class="screen" id="screen-5" data-video="vid/dandelion.mp4" data-autoslide="15000">
  19. <img src="img/dandelion.jpg" class="big-image" />
  20. <h1 class="video-title" style="color:#000">Image 5</h1>
  21. </div>
  22. </div>
  23.  
  24. <nav id="next-btn">
  25. <a href="#" class="next-icon"></a>
  26. </nav>
  27.  
  28. $(function() {
  29.  
  30. // Use Modernizr to detect for touch devices,
  31. // which don't support autoplay and may have less bandwidth,
  32. // so just give them the poster images instead
  33. var screenIndex = 1,
  34. numScreens = $('.screen').length,
  35. isTransitioning = false,
  36. transitionDur = 1000,
  37. BV,
  38. videoPlayer,
  39. isTouch = Modernizr.touch,
  40. $bigImage = $('.big-image'),
  41. $window = $(window);
  42.  
  43. if (!isTouch) {
  44. // initialize BigVideo
  45. BV = new $.BigVideo({forceAutoplay:isTouch});
  46. BV.init();
  47. showVideo();
  48.  
  49. BV.getPlayer().addEvent('loadeddata', function() {
  50. onVideoLoaded();
  51. });
  52.  
  53. // adjust image positioning so it lines up with video
  54. $bigImage
  55. .css('position','relative')
  56. .imagesLoaded(adjustImagePositioning);
  57. // and on window resize
  58. $window.on('resize', adjustImagePositioning);
  59. }
  60.  
  61. // Next button click goes to next div
  62. $('#next-btn').on('click', function(e) {
  63. e.preventDefault();
  64. if (!isTransitioning) {
  65. next();
  66. }
  67. });
  68.  
  69. function showVideo() {
  70. BV.show($('#screen-'+screenIndex).attr('data-video'),{ambient:true});
  71. }
  72.  
  73. function next() {
  74. isTransitioning = false;
  75.  
  76. // update video index, reset image opacity if starting over
  77. if (screenIndex === numScreens) {
  78. $bigImage.css('opacity',1);
  79. screenIndex = 1;
  80. } else {
  81. screenIndex++;
  82. }
  83.  
  84. if (!isTouch) {
  85. $('#big-video-wrap').transit({'left':'-100%'},transitionDur)
  86. }
  87.  
  88. (Modernizr.csstransitions)?
  89. $('.wrapper').transit(
  90. {'left':'-'+(100*(screenIndex-1))+'%'},
  91. transitionDur,
  92. onTransitionComplete):
  93. onTransitionComplete();
  94. }
  95.  
  96. function onVideoLoaded() {
  97. $('#screen-'+screenIndex).find('.big-image').transit({'opacity':0},500)
  98. }
  99.  
  100. function onTransitionComplete() {
  101. isTransitioning = false;
  102. if (!isTouch) {
  103. $('#big-video-wrap').css('left',0);
  104. showVideo();
  105. }
  106. }
  107.  
  108. function adjustImagePositioning() {
  109. $bigImage.each(function(){
  110. var $img = $(this),
  111. img = new Image();
  112.  
  113. img.src = $img.attr('src');
  114.  
  115. var windowWidth = $window.width(),
  116. windowHeight = $window.height(),
  117. r_w = windowHeight / windowWidth,
  118. i_w = img.width,
  119. i_h = img.height,
  120. r_i = i_h / i_w,
  121. new_w, new_h, new_left, new_top;
  122.  
  123. if( r_w > r_i ) {
  124. new_h = windowHeight;
  125. new_w = windowHeight / r_i;
  126. }
  127. else {
  128. new_h = windowWidth * r_i;
  129. new_w = windowWidth;
  130. }
  131.  
  132. $img.css({
  133. width : new_w,
  134. height : new_h,
  135. left : ( windowWidth - new_w ) / 2,
  136. top : ( windowHeight - new_h ) / 2
  137. })
  138.  
  139. });
  140.  
  141. }
  142. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement