main.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /**
  2. * xuequ.js
  3. * @authors qing.zhou (qing.zhou@moji.com)
  4. * @date 2014-12-17
  5. * @version 0.1
  6. */
  7. ! function(root, $, undefined) {
  8. var doc = root.document,
  9. $pages = $('.slide-page'),
  10. $arrow = $('.arrow-up'),
  11. $audioBtn = $('.btn-audio'),
  12. count = $pages.length,
  13. timeoutID = {};
  14. var now = function() {
  15. return +new Date;
  16. }
  17. var initPages = function() {
  18. $pages.pageSlider();
  19. $arrow.show();
  20. $pages.eq(0).show().next('.page').show();
  21. setTimeout(function() {
  22. $pages.eq(0).addClass('active');
  23. }, 0);
  24. $(doc).on('enter leave', function(e, data) {
  25. var $target = $(e.target);
  26. if (e.type === 'enter') {
  27. // 最后一页不现实上滑按钮
  28. if (data.index && data.index + 1 == count) {
  29. setTimeout(function() {
  30. $arrow.hide();
  31. }, 0);
  32. } else {
  33. $arrow.show()
  34. }
  35. $target.show().next('.page').show();
  36. setTimeout(function() {
  37. $target.addClass('active');
  38. }, 0)
  39. } else {
  40. $target.removeClass('active');
  41. }
  42. });
  43. var bgMusic = doc.getElementById('bg_music');
  44. $(doc).one('touchstart', function(){
  45. bgMusic.play();
  46. });
  47. $audioBtn.on("click", function() {
  48. console.log(bgMusic.paused)
  49. if (bgMusic.currentTime == 0 || bgMusic.ended || bgMusic.paused) {
  50. bgMusic.play();
  51. $audioBtn.removeClass("disabled");
  52. } else {
  53. bgMusic.pause();
  54. $audioBtn.addClass("disabled");
  55. }
  56. return false;
  57. })
  58. };
  59. var initShare = function() {
  60. var $shareBtn = $('#do_share'),
  61. $shareLayer = $('.share-dialog-bg'),
  62. $shareInfo = $('.share-info');
  63. $shareBtn.on('touchstart', function() {
  64. $shareBtn.addClass('active');
  65. }).on('touchend', function() {
  66. $shareBtn.removeClass('active');
  67. }).on('tap', function() {
  68. $shareLayer.show();
  69. $(doc).on('share:touchmove', function(e) {
  70. e.preventDefault();
  71. })
  72. });
  73. $shareLayer.on('tap', function() {
  74. $shareLayer.hide();
  75. $(doc).off('share:touchmove');
  76. });
  77. }
  78. var handleDownload = function() {
  79. var ua = navigator.userAgent.toLowerCase(),
  80. iOS = /(ipad|iphone|ipod|Macintosh)/g.test(ua),
  81. vUrl = "http://mp.weixin.qq.com/mp/redirect?url=",
  82. iosUrl = "https://itunes.apple.com/cn/app/mo-ji-tian-qi-pm2.5-shi-jing/id434209233?mt=8",
  83. androidUrl = "http://a.app.qq.com/o/simple.jsp?pkgname=com.moji.mjweather&ckey=CK1288790370865";
  84. var $download = $('#download'),
  85. url;
  86. // 判断是否在moji端内
  87. var regExpi = /mojii/,
  88. regExpa = /mojia/;
  89. // 端内隐藏
  90. if (regExpi.test(ua) || regExpa.test(ua)) {
  91. $download.hide();
  92. return;
  93. }
  94. if (/MicroMessenger/i.test(ua)) {
  95. url = vUrl + (iOS ? iosUrl : androidUrl);
  96. } else {
  97. url = iOS ? iosUrl : androidUrl;
  98. }
  99. var _oHtml = $download.html();
  100. var _html = '<a href="' + url + '">' + _oHtml + '</a>';
  101. $download.html(_html);
  102. }
  103. $(root).one('load', initPages);
  104. //滑倒最后一夜触发
  105. $pages.last().one('enter', function() {
  106. initShare();
  107. handleDownload();
  108. });
  109. }(window, Zepto)