banner.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. window.onload = function(){
  2. var Fadetext = {};
  3. Fadetext.arow = 0;
  4. Fadetext.Flag = false;
  5. Fadetext.viewWidth = document.body.clientWidth;
  6. Fadetext.viewHeight = (window.innerHeight) ? window.innerHeight : document.body.clientHeight;
  7. Fadetext.offsetdom = [];
  8. Fadetext.offsetinx = [];
  9. Fadetext.init = function(option){
  10. this.option = $.extend({},option);
  11. this.className = this.option.className || '';
  12. this.speed = this.option.speed || '';
  13. this.bindCarousely();
  14. }
  15. Fadetext.bindCarousely = function(){
  16. var $progress = $('.swiper-pagination-two');
  17. var $img = $('.slipe-box').find('.swiper-slide');
  18. var $k = $('.section-img').find('img');
  19. var mySwiper = new Swiper('.slider-two',{
  20. loop : true,
  21. autoplay : 5000,
  22. speed:800,
  23. prevButton:'.slipe-left',
  24. nextButton:'.slipe-right',
  25. pagination : '.swiper-pagination-two',
  26. paginationClickable :true,
  27. autoplayDisableOnInteraction : false,
  28. paginationBulletRender: function (swiper, index, className) {
  29. return '<div class="' + className + '"><p></p></div>';
  30. },
  31. onTransitionEnd: function(swiper){
  32. if(swiper.activeIndex == 1){
  33. setTimeout(function() {
  34. $progress.find('div').eq(0).find('p').addClass('login');
  35. }, 1);
  36. }
  37. $progress.find('p').removeClass('login');
  38. $progress.find('div').eq(swiper.activeIndex == swiper.imagesLoaded - 1 ? 0 : swiper.activeIndex - 1).find('p').addClass('login');
  39. },
  40. onSlideChangeStart: function(swiper){
  41. $k.eq(swiper.activeIndex == swiper.imagesLoaded - 1 ? 0 : swiper.activeIndex - 1).css('opacity','1').siblings().css('opacity','0');
  42. }
  43. })
  44. $(document).on('mousemove mouseout',".slipe-box .swiper-wrapper",function(e) {
  45. if(e.type === 'mousemove'){
  46. // (Fadetext.viewWidth / 2 > e.pageX) ? $('.slipe-left').addClass('arowshow').siblings('.slipe-right').removeClass('arowshow') : $('.slipe-right').addClass('arowshow').siblings('.slipe-left').removeClass('arowshow');
  47. $('.slipe-left,.slipe-right').addClass('arowshow');
  48. }else{
  49. $('.slipe-left,.slipe-right').removeClass('arowshow');
  50. }
  51. })
  52. //this.bindScroll();
  53. }
  54. Fadetext.bindScroll = function(){
  55. var a = c = d = e = 0,
  56. $flag = $index = 0,
  57. node = (!!window.ActiveXObject || "ActiveXObject" in window) ? "body" : document;
  58. $('.animate-text').each(function(){
  59. var a = 'a' + parseInt($(this).offset().top);
  60. var o = {
  61. index : a.substr(1),
  62. doma : $(this)
  63. }
  64. Fadetext.offsetinx.push(o);
  65. })
  66. Fadetext.offsetdom[0] = Fadetext.offsetinx[0];
  67. for(var i = 1 ; i < Fadetext.offsetinx.length; i++){
  68. var f = true;
  69. for(var j = 0 ; j < Fadetext.offsetdom.length; j++){
  70. if(Fadetext.offsetinx[i].index == Fadetext.offsetdom[j].index){
  71. f = false;
  72. Fadetext.offsetdom[j].doma.push(Fadetext.offsetinx[i].doma);
  73. }
  74. }
  75. if(f){
  76. var o = {
  77. index : Fadetext.offsetinx[i].index,
  78. doma : [Fadetext.offsetinx[i].doma]
  79. }
  80. Fadetext.offsetdom.push(o);
  81. }
  82. f = true;
  83. }
  84. Fadetext.offsetinx = [];
  85. $('.animate-img').each(function(){
  86. var a = 'a' + parseInt($(this).offset().top);
  87. var o = {
  88. index : a.substr(1),
  89. doma : $(this)
  90. }
  91. Fadetext.offsetinx.push(o);
  92. })
  93. window.scroll(0,$(document).scrollTop() + 1);
  94. $(window).resize(function() {
  95. window.location.reload();
  96. });
  97. var beforeScrollTop = document.body.scrollTop,
  98. fn = fn || function() {},
  99. fx = true;
  100. $(window).scroll(function (){
  101. var b = $(window).scrollTop() + $(window).height();
  102. var p = $(this).scrollTop();
  103. var afterScrollTop = document.body.scrollTop,
  104. delta = afterScrollTop - beforeScrollTop;
  105. fx = ( delta > 0 ? false : true );
  106. beforeScrollTop = afterScrollTop;
  107. for(var i = 0 ; i < Fadetext.offsetdom.length; i++ ){
  108. var vala = Fadetext.offsetdom[i];
  109. //到元素位置显示动画
  110. if ( (Fadetext.viewHeight + p) >= parseInt(vala.index)) {
  111. var valb = vala.doma;
  112. for(var j = 0 ; j < vala.doma.length ; j++){
  113. if($(vala.doma[j]).attr('data-lazy') === 'lazy'){
  114. if(Fadetext.Flag && (Fadetext.viewHeight + p) >= parseInt(vala.index) + 3070){
  115. $(vala.doma[j]).addClass('animate-position');
  116. }
  117. else if (!Fadetext.Flag){
  118. $(vala.doma[j]).addClass('animate-position');
  119. }
  120. }else{
  121. $(vala.doma[j]).addClass('animate-position');
  122. }
  123. //到位置数字滚动效果
  124. if($(vala.doma[j]).attr('data-type') === 'num'){
  125. if(Fadetext.Flag && (Fadetext.viewHeight + p) >= parseInt(vala.index) + 3070){
  126. Fadetext.numRun1.resetData('1000000');
  127. Fadetext.numRun2.resetData('15000');
  128. Fadetext.numRun3.resetData('1000');
  129. Fadetext.numRun4.resetData('100');
  130. }
  131. else if (!Fadetext.Flag){
  132. Fadetext.numRun1.resetData('1000000');
  133. Fadetext.numRun2.resetData('15000');
  134. Fadetext.numRun3.resetData('1000');
  135. Fadetext.numRun4.resetData('100');
  136. }
  137. }
  138. }
  139. }
  140. }
  141. for(var j = 0 ; j < Fadetext.offsetinx.length; j++){
  142. var vala = Fadetext.offsetinx[j];
  143. //图片视差滚动 1
  144. if(b > parseInt(vala.index) + 900 && $(vala.doma[j]).attr('data-type') === 'one'){
  145. if(p < parseInt(vala.index) + 1000 && a < 40){
  146. if(this.arow){
  147. a -= 0.2;
  148. }else{
  149. a += 0.2;
  150. }
  151. }else if(p < parseInt(vala.index) + 400 && a > 40){
  152. a -= 0.3;
  153. }
  154. else{
  155. a = 0;
  156. }
  157. $(vala.doma[j]).css("transform", "translate3d(0%," + a + "% , 0)");
  158. }
  159. //图片视差滚动 2
  160. if (b > 2235 && Fadetext.Flag) {
  161. if(p < 2400 && Math.abs(d) < 150){
  162. if(fx){
  163. d += 0.03;
  164. }else{
  165. d -= 0.03;
  166. }
  167. }
  168. else{
  169. d = 0;
  170. }
  171. // console.log(d);
  172. $('.animate-img[data-type="two"]').css("transform", "translate3d(0%," + d + "px , 0)");
  173. }
  174. //图片视差滚动 3
  175. if (p > 3853 && Fadetext.Flag) {
  176. if(p < 4200 && Math.abs(c) < 8){
  177. if(this.arow){
  178. c += 0.007;
  179. }else{
  180. c -= 0.007;
  181. }
  182. }else if(p < 4200 && Math.abs(c) < 8){
  183. c += 0.007;
  184. }
  185. else{
  186. c = 0;
  187. }
  188. $('.animate-img[data-type="three"]').css("transform", "translate3d(0%," + c + "% , 0)");
  189. }
  190. }
  191. });
  192. }
  193. //初始化
  194. var init = function(){};
  195. Fadetext.init();
  196. }