homerelevant.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. // 2018-10-11 轮播图
  2. var mySwiper1= new Swiper("#m_swiper",{
  3. loop : true,
  4. loopedSlides:4,
  5. // autoplay:5500,
  6. // centeredSlides: true, //居中展示
  7. spaceBetween:10, //间距20px
  8. autoplayDisableOnInteraction : false,
  9. // 如果需要分页器
  10. pagination: '.swiper-pagination',
  11. slidesPerView :"auto",
  12. });
  13. //获取url中的参数
  14. function getUrlParam(name){
  15. //构造一个含有目标参数的正则表达式对象
  16. var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  17. //匹配目标参数
  18. var r = window.location.search.substr(1).match(reg);
  19. //alert(r);
  20. //返回参数值
  21. if (r!=null) return decodeURI(r[2]);
  22. return null;
  23. }
  24. // 筛选 选中效果
  25. var _city = getUrlParam('city'); //价格
  26. if (_city) {
  27. var _index = $('.videoclick li[country="'+_city+'"]').index();
  28. };
  29. //demo示例六 通过id调取 底部菜单插件
  30. $('#demo06').navbarscroll({
  31. defaultSelect:_index,
  32. scrollerWidth:6,
  33. fingerClick:1,
  34. endClickScroll:function(obj){
  35. // console.log(obj.text())
  36. }
  37. });
  38. // ---------------------------------------------------
  39. function getParams(url) {
  40. var theRequest = new Object();
  41. if (!url)
  42. url = location.href;
  43. if (url.indexOf("?") !== -1)
  44. {
  45. var str = url.substr(url.indexOf("?") + 1) + "&";
  46. var strs = str.split("&");
  47. for (var i = 0; i < strs.length - 1; i++)
  48. {
  49. var key = strs[i].substring(0, strs[i].indexOf("="));
  50. var val = strs[i].substring(strs[i].indexOf("=") + 1);
  51. theRequest[key] = val;
  52. }
  53. }
  54. return theRequest;
  55. }
  56. var objUrl = {}; //获取get参数
  57. var url = window.location.href;
  58. var searchParams = ''; //最后拼接的参数
  59. var urlParams = '';
  60. // 页数
  61. var page = 1;
  62. // 每页展示5个
  63. var size = 10;
  64. var params = getParams(url); //获取get请求的参数
  65. if(!$.isEmptyObject(params)){
  66. $.each(params,function(key,val){
  67. if(key == 'city') feng_cityTel = val;
  68. objUrl[key] = val;
  69. urlParams += key+'='+val+'&';
  70. })
  71. urlParams = urlParams.substring(0,urlParams.length - 1);
  72. searchParams = '&'+ urlParams;
  73. }
  74. var country = $('.videoclick li').eq(0).attr('country');
  75. $('.videoclick li').on('click',function(){
  76. var _this = $(this);
  77. country = $(this).attr('country');
  78. var ParamsArr = ['city']; //搜索字段
  79. var atrName = _this.attr('name');
  80. var _val = _this.attr('country');
  81. var urlParams = '';
  82. for (var k in ParamsArr){
  83. if(ParamsArr[k] == atrName){
  84. objUrl[atrName] = _val;
  85. delete objUrl.page;
  86. }
  87. }
  88. $.each(objUrl,function(key,val){
  89. if(key == 'py') return true; //跳出当前循环
  90. urlParams += key+'='+val+'&';
  91. })
  92. var cityUrl = '';
  93. urlParams = urlParams.substring(0,urlParams.length - 1);
  94. if(typeof objUrl.py == 'string'){
  95. cityUrl = 'py='+objUrl.py+'&';
  96. }
  97. if(urlParams == '' && cityUrl != '')
  98. {
  99. cityUrl = cityUrl.substring(0,cityUrl.length - 1);
  100. }
  101. window.location.href = '/video/homerelevant?'+ cityUrl+urlParams;
  102. })
  103. $(function(){
  104. $('.m_videolist_box').dropload({
  105. scrollArea : window,
  106. domDown : {
  107. domClass : 'dropload-down',
  108. domRefresh : '<div class="dropload-refresh">↑上拉加载更多</div>',
  109. domLoad : '<div class="dropload-load"><span class="loading"></span>加载中...</div>',
  110. domNoData : '<div class="dropload-noData">我也是有底线的...</div>'
  111. },
  112. loadDownFn : function(me,da){
  113. page++;
  114. // 拼接HTML
  115. var result = '';
  116. $.ajax({
  117. type: 'GET',
  118. url: '/video/relevantdata?page='+page+'&limit='+size+searchParams+'&hid='+country,
  119. dataType: 'json',
  120. async:false,
  121. success: function(data){
  122. var data = data.data;
  123. // console.log(data);
  124. if(data != null){
  125. $.each(data,function (key,val) {
  126. result+= '<li class="m_hxt_imglist item">';
  127. result+= '<a href="/video/relevantdetails/'+val.id+'">';
  128. result+= '<div class="m_videolist_img">';
  129. result+= '<img class="img" src="'+val.thumb+'" alt="">';
  130. result+= '<i><img src="/video/image/video5.png" alt="">'+val.up_city+'·'+val.city_name+'</i>';
  131. result+= '<div class="m_videolist_text">';
  132. result+= '<p>';
  133. result+= '<span class="time_b">00:00</span>';
  134. result+= '</p>';
  135. result+= '</div>';
  136. result+= '</div>';
  137. result+= ' <div class="text">';
  138. var str = val.title;
  139. var _length = val.title.length;
  140. str = str.substr(0,36) + '...' ;
  141. if(_length > 36){
  142. result+= '<p class="title">'+str+'</p>';
  143. }else{
  144. result+= '<p class="title">'+val.title+'</p>';
  145. }
  146. result+= '<p class="dj c"><span><img src="/video/image/video6.png" alt="">'+(val.plays * 1 + 999)+'观看</span></p>';
  147. result+= '</div>';
  148. result+= '<video class="video_list_main" style="display:none;">';
  149. result+= '<source src="'+val.video_url+'" type="video/mp4">';
  150. result+= '</video>';
  151. result+= '</a>';
  152. result+= '</li>';
  153. })
  154. // console.log(result[1]);
  155. $('.m_videolist').append(result);
  156. myFunction($('.m_videolist_box ul li'));
  157. // 如果没有数据
  158. }else{
  159. // 锁定
  160. me.lock();
  161. // 无数据
  162. me.noData();
  163. }
  164. me.resetload();
  165. // 为了测试,延迟1秒加载
  166. // setTimeout(function(){
  167. // // 插入数据到页面,放到最后面
  168. // $('.y_hotnews_list ul').append(result);
  169. // // 每次数据插入,必须重置
  170. // me.resetload();
  171. // },100);
  172. },
  173. error: function(xhr, type){
  174. // alert('Ajax error!');
  175. // 即使加载出错,也得重置
  176. me.resetload();
  177. }
  178. });
  179. }
  180. });
  181. });
  182. // 获取 "video" 视频元素时长
  183. function myFunction(cid){
  184. cid.each(function(){
  185. var _this=$(this)
  186. _this.find('video.video_list_main')[0].addEventListener("loadedmetadata", function(){
  187. var tol = this.duration;//获取总时长
  188. var time = parseInt(tol);
  189. var minutes = parseInt(time / 60);
  190. var seconds =( time - minutes * 60);
  191. _this.find('.time_b').html(Appendzero(minutes)+':'+Appendzero(seconds))
  192. })
  193. })
  194. }
  195. function Appendzero (obj) { //时间补零
  196. if (obj < 10) return "0" + obj; else return obj;
  197. }
  198. $(document).keydown(function(event){
  199. if(event.keyCode==13){
  200. var txt = $('.y_lplist_inp').val();
  201. if (txt != '') {
  202. window.location.href = '/video/homerelevant?name='+ txt;
  203. };
  204. }
  205. });