components.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. // 通用数据
  2. let globaldata = {
  3. // 滚动高度
  4. scrollheight: 50,
  5. // body
  6. body: document.documentElement || document.body
  7. }
  8. // 大屏 下拉菜单
  9. $(
  10. function () {
  11. let navitems = $("#nav>.nav-item");
  12. const move = (that, show) => {
  13. let lis = $(that).find("li"),
  14. i = $(that).find("i");
  15. ul = $(that).find("ul");
  16. if (lis.length != 0 && show) {
  17. ul.addClass("show");
  18. i.removeClass("glyphicon-chevron-down").addClass("glyphicon-chevron-up");
  19. return false;
  20. }
  21. if (lis.length != 0 && !show) {
  22. ul.removeClass("show")
  23. i.removeClass("glyphicon-chevron-up").addClass("glyphicon-chevron-down");
  24. return false;
  25. }
  26. return false;
  27. }
  28. for (let i = 0; i < navitems.length; i++) {
  29. $(navitems[i]).mouseenter(function () {
  30. let that = this;
  31. move(that, true)
  32. }).mouseleave(function () {
  33. let that = this;
  34. move(that, false)
  35. })
  36. }
  37. }
  38. )
  39. // 监听滚动轴
  40. $(function () {
  41. // face显示锁
  42. let lock = true;
  43. // top显示锁
  44. let locktop = false;
  45. // 滚动高度
  46. let height = globaldata.scrollheight;
  47. $("body")[0].onscroll = function () {
  48. let stop = globaldata.body.scrollTop;
  49. // console.log(stop)
  50. // 可是区域宽度;
  51. if (stop > height && !locktop) {
  52. $("#top").removeClass("noshow");
  53. locktop = true;
  54. }
  55. if (stop < height && locktop) {
  56. $("#top").addClass("noshow");
  57. locktop = false;
  58. }
  59. if ($("body")[0].clientWidth < 768) {
  60. return false;
  61. }
  62. if (stop > height && lock) {
  63. $("#face").addClass("noshow");
  64. lock = false
  65. return false;
  66. }
  67. if (stop <= height && !lock) {
  68. $("#face").removeClass("noshow");
  69. lock = true;
  70. return false;
  71. }
  72. }
  73. })
  74. // 小屏幕 下拉菜单
  75. $(function () {
  76. // 按钮开关
  77. let lock = false;
  78. const open = () => {
  79. if (!lock) {
  80. $("#nav-sm").addClass("nav-sm-show").removeClass("nav-sm-noshow");
  81. globaldata.body.addEventListener('touchmove', e =>
  82. e.preventDefault()
  83. , { passive: false })
  84. lock = true
  85. return false;
  86. }
  87. if (lock) {
  88. $("#nav-sm").addClass("nav-sm-noshow").removeClass("nav-sm-show");
  89. globaldata.body.removeEventListener('touchmove', e => e.preventDefault() = true, { passive: false })
  90. lock = false;
  91. return false;
  92. }
  93. }
  94. $('#listbutton').click(function () {
  95. open()
  96. })
  97. // 可视区域变化
  98. window.onresize = () => {
  99. let appwidth = $("body")[0].clientWidth;
  100. if (appwidth > 768) {
  101. $("#nav-sm").removeClass("nav-sm-show");
  102. lock = false;
  103. return false;
  104. } else {
  105. // face 移动端显示
  106. try {
  107. $("#face").removeClass("noshow");
  108. } catch (err) { }
  109. }
  110. // if (lock) {
  111. // $("#nav-sm").addClass("nav-sm-show");
  112. // return false;
  113. // }
  114. }
  115. })
  116. // 分享设置
  117. var shareModel = {
  118. // /**
  119. // * 分享QQ好友
  120. // * @param {[type]} title [分享标题]
  121. // * @param {[type]} url [分享url链接,默认当前页面链接]
  122. // * @param {[type]} pic [分享图片]
  123. // * @return {[type]} [description]
  124. // */
  125. shareQQ: function (url, title, pic) {
  126. var param = {
  127. url: url || window.location.href,
  128. desc: '', /*分享理由*/
  129. title: title || '', /*分享标题(可选)*/
  130. summary: '',/*分享描述(可选)*/
  131. pics: pic || '',/*分享图片(可选)*/
  132. flash: '', /*视频地址(可选)*/
  133. site: '' /*分享来源 (可选) */
  134. };
  135. var s = [];
  136. for (var i in param) {
  137. s.push(i + '=' + encodeURIComponent(param[i] || ''));
  138. }
  139. var targetUrl = "https://connect.qq.com/widget/shareqq/iframe_index.html?" + s.join('&');
  140. window.open(targetUrl, 'qq');
  141. },
  142. // /**
  143. // * 微信分享
  144. // * @return {[type]} [description]
  145. // */
  146. weixin: function () {
  147. var url = window.location.href,
  148. encodePath = encodeURIComponent(url),
  149. targetUrl = 'https://api.gaokaozhitongche.com/v1/direct?text=' + encodePath;
  150. window.open(targetUrl, 'weixin');
  151. },
  152. // /**
  153. // * 分享新浪微博
  154. // * @param {[type]} title [分享标题]
  155. // * @param {[type]} url [分享url链接,默认当前页面]
  156. // * @param {[type]} pic [分享图片]
  157. // * @return {[type]} [description]
  158. // */
  159. sinaWeiBo: function (title, url, pic) {
  160. var param = {
  161. url: url || window.location.href,
  162. type: '3',
  163. count: '1', /** 是否显示分享数,1显示(可选)*/
  164. appkey: '', /** 您申请的应用appkey,显示分享来源(可选)*/
  165. title: '', /** 分享的文字内容(可选,默认为所在页面的title)*/
  166. pic: pic || '', /**分享图片的路径(可选)*/
  167. ralateUid: '', /**关联用户的UID,分享微博会@该用户(可选)*/
  168. rnd: new Date().valueOf()
  169. }
  170. var temp = [];
  171. for (var p in param) {
  172. temp.push(p + '=' + encodeURIComponent(param[p] || ''))
  173. }
  174. var targetUrl = 'https://service.weibo.com/share/share.php?' + temp.join('&');
  175. window.open(targetUrl, 'sinaweibo');
  176. }
  177. };
  178. $(function () {
  179. $("#share").mouseenter(function () {
  180. $(this).children("ul").css("width", 'auto')
  181. }).mouseleave(function () {
  182. $(this).children("ul").css("width", '0px')
  183. })
  184. let lis = $("#share>ul>li");
  185. for (let i = 0; i < lis.length; i++) {
  186. if (i == 1) {
  187. $(lis[i]).click(function () {
  188. shareModel.shareQQ();
  189. })
  190. }
  191. // if (i == 2) {
  192. // $(lis[i]).click(function () {
  193. // shareModel.weixin(url = "https://app.gaokaozhitongche.com/");
  194. // })
  195. // }
  196. if (i == 2) {
  197. $(lis[i]).click(function () {
  198. console.log(1)
  199. shareModel.sinaWeiBo();
  200. })
  201. }
  202. }
  203. })
  204. // 按钮锁
  205. $(function () {
  206. $("#top").click(function () {
  207. let dom = globaldata.body;
  208. // let top = document.documentElement.scrollTop || document.body.scrollTop;
  209. $(dom).animate({ scrollTop: 0 }, 500);
  210. })
  211. })
  212. // toast 背景事件
  213. $(function () {
  214. $("#toast").click(function (e) {
  215. if (e.target.id != 'toast') return false
  216. $(this).removeClass("show");
  217. Array.prototype.slice.call($(this).find(".show")).forEach(e => {
  218. $(e).removeClass("show")
  219. })
  220. })
  221. })