homevideo.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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/homevideo?'+ 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/homevideodata?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>';
  127. result+= '<a href="/video/videodetails/'+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 class="c">';
  133. result+= '<span><img src="/video/image/video7.png" alt="">'+(val.plays * 1 + 999)+'观看</span>';
  134. result+= '<span>00:00</span>';
  135. result+= '</p>';
  136. result+= '</div>';
  137. result+= '</div>';
  138. result+= '<div class="text">';
  139. result+= '<p class="name">'+val.name+'</p>';
  140. result+= '<p class="jg">¥<i>'+val.price+'</i>'+val.price_nuit+'</p>';
  141. result+= '<p class="yxq">有效期至:'+val.time+'</p>';
  142. result+= '</div>';
  143. result+= '<video class="video_list_main" style="display:none;">';
  144. result+= '<source src="'+val.video+'" type="video/mp4">';
  145. result+= '</video>';
  146. result+= '</a>';
  147. result+= '</li>';
  148. })
  149. $('.m_videolist').append(result);
  150. myFunction($('.m_videolist_box ul li'));
  151. // 如果没有数据
  152. }else{
  153. // 锁定
  154. me.lock();
  155. // 无数据
  156. me.noData();
  157. }
  158. me.resetload();
  159. // 为了测试,延迟1秒加载
  160. // setTimeout(function(){
  161. // // 插入数据到页面,放到最后面
  162. // $('.y_hotnews_list ul').append(result);
  163. // // 每次数据插入,必须重置
  164. // me.resetload();
  165. // },100);
  166. },
  167. error: function(xhr, type){
  168. // alert('Ajax error!');
  169. // 即使加载出错,也得重置
  170. me.resetload();
  171. }
  172. });
  173. }
  174. });
  175. });
  176. // 获取 "video" 视频元素时长
  177. function myFunction(cid){
  178. cid.each(function(){
  179. var _this=$(this)
  180. _this.find('video.video_list_main')[0].addEventListener("loadedmetadata", function(){
  181. var tol = this.duration;//获取总时长
  182. var time = parseInt(tol);
  183. var minutes = parseInt(time / 60);
  184. var seconds =( time - minutes * 60);
  185. _this.find('.time_b').html(Appendzero(minutes)+':'+Appendzero(seconds))
  186. })
  187. })
  188. }
  189. function Appendzero (obj) { //时间补零
  190. if (obj < 10) return "0" + obj; else return obj;
  191. }
  192. myFunction($('.m_videolist_box ul li'));
  193. $(document).keydown(function(event){
  194. if(event.keyCode==13){
  195. var txt = $('.y_lplist_inp').val();
  196. if (txt != '') {
  197. window.location.href = '/video/homevideo?name='+ txt;
  198. };
  199. }
  200. });