index.js 6.0 KB

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