custom.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /* smooth scroll */
  2. $(function() {
  3. $('a[href*=#]:not([href=#])').click(function() {
  4. if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') || location.hostname == this.hostname) {
  5. var target = $(this.hash);
  6. target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
  7. if (target.length) {
  8. $('html,body').animate({
  9. scrollTop: target.offset().top
  10. }, 1000);
  11. return false;
  12. }
  13. }
  14. });
  15. });
  16. /* scrollspy */
  17. $('body').scrollspy({ target: '#navbar-scroll' })
  18. // Closes the Responsive Menu on Menu Item Click
  19. $('.navbar-collapse ul li a').click(function() {
  20. $('.navbar-toggle:visible').click();
  21. });
  22. /* carousel */
  23. $(document).ready(function() {
  24. $("#screenshots").owlCarousel({
  25. items: 4,
  26. itemsCustom : [
  27. [0, 1],
  28. [480, 2],
  29. [768, 3],
  30. [992, 4]
  31. ],
  32. });
  33. $("#owl-testi").owlCarousel
  34. ({
  35. navigation : false, // Show next and prev buttons
  36. slideSpeed : 300,
  37. autoHeight : true,
  38. singleItem:true
  39. });
  40. });
  41. /* sticky navigation */
  42. $(document).ready(function(){
  43. $("#menu").sticky({topSpacing:0});
  44. });
  45. jQuery(document).ready(function($) {
  46. // site preloader -- also uncomment the div in the header and the css style for #preloader
  47. $(window).load(function(){
  48. $('#preloader').fadeOut('slow',function(){$(this).remove();});
  49. });
  50. });
  51. /* scrollToTop */
  52. $(document).ready(function(){
  53. //Check to see if the window is top if not then display button
  54. $(window).scroll(function(){
  55. if ($(this).scrollTop() > 500) {
  56. $('.scrollToTop').fadeIn();
  57. } else {
  58. $('.scrollToTop').fadeOut();
  59. }
  60. });
  61. //Click event to scroll to top
  62. $('.scrollToTop').click(function(){
  63. $('html, body').animate({scrollTop : 0},800);
  64. return false;
  65. });
  66. });
  67. /* parallax background image http://www.minimit.com/articles/lets-animate/parallax-backgrounds-with-centered-content
  68. /* detect touch */
  69. if("ontouchstart" in window){
  70. document.documentElement.className = document.documentElement.className + " touch";
  71. }
  72. if(!$("html").hasClass("touch")){
  73. /* background fix */
  74. $(".parallax").css("background-attachment", "fixed");
  75. }
  76. /* fix vertical when not overflow
  77. call fullscreenFix() if .fullscreen content changes */
  78. function fullscreenFix(){
  79. var h = $('body').height();
  80. // set .fullscreen height
  81. $(".content-b").each(function(i){
  82. if($(this).innerHeight() <= h){
  83. $(this).closest(".fullscreen").addClass("not-overflow");
  84. }
  85. });
  86. }
  87. $(window).resize(fullscreenFix);
  88. fullscreenFix();
  89. /* resize background images */
  90. function backgroundResize(){
  91. var windowH = $(window).height();
  92. $(".landing, .action, .contact, .subscribe").each(function(i){
  93. var path = $(this);
  94. // variables
  95. var contW = path.width();
  96. var contH = path.height();
  97. var imgW = path.attr("data-img-width");
  98. var imgH = path.attr("data-img-height");
  99. var ratio = imgW / imgH;
  100. // overflowing difference
  101. var diff = parseFloat(path.attr("data-diff"));
  102. diff = diff ? diff : 0;
  103. // remaining height to have fullscreen image only on parallax
  104. var remainingH = 0;
  105. if(path.hasClass("parallax") && !$("html").hasClass("touch")){
  106. var maxH = contH > windowH ? contH : windowH;
  107. remainingH = windowH - contH;
  108. }
  109. // set img values depending on cont
  110. imgH = contH + remainingH + diff;
  111. imgW = imgH * ratio;
  112. // fix when too large
  113. if(contW > imgW){
  114. imgW = contW;
  115. imgH = imgW / ratio;
  116. }
  117. //
  118. path.data("resized-imgW", imgW);
  119. path.data("resized-imgH", imgH);
  120. path.css("background-size", imgW + "px " + imgH + "px");
  121. });
  122. }
  123. $(window).resize(backgroundResize);
  124. $(window).focus(backgroundResize);
  125. backgroundResize();
  126. /* set parallax background-position */
  127. function parallaxPosition(e){
  128. var heightWindow = $(window).height();
  129. var topWindow = $(window).scrollTop();
  130. var bottomWindow = topWindow + heightWindow;
  131. var currentWindow = (topWindow + bottomWindow) / 2;
  132. $(".parallax").each(function(i){
  133. var path = $(this);
  134. var height = path.height();
  135. var top = path.offset().top;
  136. var bottom = top + height;
  137. // only when in range
  138. if(bottomWindow > top && topWindow < bottom){
  139. var imgW = path.data("resized-imgW");
  140. var imgH = path.data("resized-imgH");
  141. // min when image touch top of window
  142. var min = 0;
  143. // max when image touch bottom of window
  144. var max = - imgH + heightWindow;
  145. // overflow changes parallax
  146. var overflowH = height < heightWindow ? imgH - height : imgH - heightWindow; // fix height on overflow
  147. top = top - overflowH;
  148. bottom = bottom + overflowH;
  149. // value with linear interpolation
  150. var value = min + (max - min) * (currentWindow - top) / (bottom - top);
  151. // set background-position
  152. var orizontalPosition = path.attr("data-oriz-pos");
  153. orizontalPosition = orizontalPosition ? orizontalPosition : "50%";
  154. $(this).css("background-position", orizontalPosition + " " + value + "px");
  155. }
  156. });
  157. }
  158. if(!$("html").hasClass("touch")){
  159. $(window).resize(parallaxPosition);
  160. //$(window).focus(parallaxPosition);
  161. $(window).scroll(parallaxPosition);
  162. parallaxPosition();
  163. }