ohplay.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**
  2. *
  3. * @authors Your Name (you@example.org)
  4. * @date 2017-08-02 17:23:52
  5. * @version $Id$
  6. */
  7. var langInit = function () {
  8. var langObj = {
  9. cn: '简体',
  10. gb: '繁体',
  11. en: 'EN'
  12. };
  13. var currentLang = TD.util.getQuery('lang');
  14. // 根据当前语言设置导航栏的语言显示
  15. if (currentLang !== '') {
  16. $('.nav-lang-current').html('<div class="nav-lang-item">' + langObj[currentLang] + '</div>')
  17. $('.lang-' + currentLang).hide();
  18. } else {
  19. $('.lang-cn').hide();
  20. };
  21. // 事件委托
  22. $('.nav-lang-hidden').on('click', function () {
  23. var target = window.event.target || window.event.srcElement;
  24. if (target.nodeName.toLowerCase() === 'li') {
  25. // 识别选取的语言并转换成xx格式
  26. var nextLang = $(target).attr('class').match(/lang\-(cn|gb|en)/g).toString().replace('lang-', '');
  27. TD.util.setCookie('lang',nextLang,7);
  28. if (currentLang !== '') {
  29. location.href = location.href.replace('lang=' + currentLang, 'lang=' + nextLang);
  30. } else if (TD.util.getQuery('=')) {
  31. location.href += '&lang=' + nextLang;
  32. } else {
  33. location.href += '?lang=' + nextLang;
  34. };
  35. };
  36. });
  37. };
  38. var pageInit = function () {
  39. langInit();
  40. $('.m-maofm').fullpage({
  41. easingcss3: 'cubic-bezier(.62,.01,0,1)',
  42. onLeave: function (index, nextIndex, direction) {
  43. console.log(index, nextIndex, direction);
  44. var sectionNow = $('.m-maofm' + '>:nth-child(' + index + ')').find('.video');
  45. var sectionNext = $('.m-maofm' + '>:nth-child(' + nextIndex + ')').find('.video');
  46. if (nextIndex === 2 || nextIndex === 10) {
  47. sectionNext.get(0).currentTime = 0;
  48. sectionNext.get(0).play();
  49. } else if (index === 2 || index === 10) {
  50. sectionNow.get(0).pause();
  51. }
  52. }
  53. // scrollOverflow: true
  54. });
  55. TD.imgPreload(function () {
  56. $('.m-loading').fadeOut(300);
  57. });
  58. // $('.m-loading').fadeOut(300);
  59. $('.maofm-2 .btn-videoplay').on('click', function () {
  60. $('.maofm-2 .video-wrap-2').show();
  61. $('.maofm-2 .video').get(0).pause();
  62. $('.maofm-2 .video-2').get(0).play();
  63. });
  64. $('.maofm-2 .video-wrap-2').on('click', function (e) {
  65. console.log(e.target.nodeName);
  66. if (e.target.nodeName === 'VIDEO') {
  67. return;
  68. };
  69. $('.maofm-2 .video-wrap-2').hide();
  70. $('.maofm-2 .video-2').get(0).pause();
  71. });
  72. $('.maofm-10 .btn-videoplay').on('click', function () {
  73. $('.maofm-10 .video-wrap-2').show();
  74. $('.maofm-10 .video').get(0).pause();
  75. $('.maofm-10 .video-2').get(0).play();
  76. });
  77. $('.maofm-10 .video-wrap-2').on('click', function (e) {
  78. if (e.target.nodeName === 'VIDEO') {
  79. return;
  80. };
  81. $('.maofm-10 .video-wrap-2').hide();
  82. $('.maofm-10 .video-2').get(0).pause();
  83. });
  84. var ratio = $('.video-wrap .video').width() / $('.video-wrap .video').height();
  85. console.log(ratio);
  86. if (window.innerWidth / window.innerHeight < ratio) {
  87. $('.video-wrap .video').css('width', 'auto');
  88. $('.video-wrap .video').css('height', '100%');
  89. }
  90. var rszEvt = 'orientationchange' in window ? 'orientationchange' : 'resize';
  91. window.addEventListener(rszEvt, function () {
  92. console.log('resize');
  93. if (window.innerWidth / window.innerHeight < ratio) {
  94. $('.video-wrap .video').css('width', 'auto');
  95. $('.video-wrap .video').css('height', '100%');
  96. } else {
  97. $('.video-wrap .video').css('width', '100%');
  98. $('.video-wrap .video').css('height', 'auto');
  99. }
  100. });
  101. }
  102. $(document).ready(function () {
  103. pageInit();
  104. })