lpalbumdetails.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. /*-------------------- 获取地址栏地址并拆分 --------------------------------*/
  2. function getParams(url) {
  3. var theRequest = new Object();
  4. if (!url)
  5. url = location.href;
  6. if (url.indexOf("?") !== -1)
  7. {
  8. var str = url.substr(url.indexOf("?") + 1) + "&";
  9. var strs = str.split("&");
  10. for (var i = 0; i < strs.length - 1; i++)
  11. {
  12. var key = strs[i].substring(0, strs[i].indexOf("="));
  13. var val = strs[i].substring(strs[i].indexOf("=") + 1);
  14. theRequest[key] = val;
  15. }
  16. }
  17. return theRequest;
  18. }
  19. var objUrl = {}; //获取get参数
  20. var url = window.location.href;
  21. var params = getParams(url);
  22. if(!$.isEmptyObject(params)){
  23. $.each(params,function(key,val){
  24. objUrl[key] = val;
  25. })
  26. }
  27. var lpid=$('.lpalbum').attr('data-hid');
  28. var album_id = 0;
  29. var oindex = 0;
  30. var thisLi='';
  31. var urlid=objUrl.daid;
  32. var videoR=$('.showimg_center .y_v3videoBox').attr('url');
  33. var videoImg=$('.showimg_center .y_v3videoBox').attr('data-img');
  34. //进入页面默认加载 相册列表出过来的默认参数 并给添加选中效果
  35. $(function(){
  36. $('.lpalbumBox_rNav a').on('click',function(){
  37. var that = $(this);
  38. album_id =that.attr('album-id');
  39. var typeName=that.attr('type-name')
  40. if (album_id!=0 && typeName!='videourl') {
  41. $('.img_c_cin').html('查看原图')
  42. if (album_id!=objUrl.album_id) {
  43. urlid=0;
  44. };
  45. oindex=0;
  46. $('.showimg_center .y_v3videoBox').hide();
  47. // console.log(album_id)
  48. that.addClass('on').siblings().removeClass('on');
  49. var _html="";
  50. // 初始化变量并赋值
  51. var minindex = 0; // 小图所在的下标
  52. var minlength = 0; // 小图所有的总数
  53. // 以三行 unbind 解除绑定事件,是为了多次点导航时,执行次的原因
  54. $('.lpalbumBox_l .prev-btn').unbind();
  55. $('.lpalbumBox_l .next-btn').unbind();
  56. $('.tulist .tulist_main ul li').unbind();
  57. $('.tulist_main ul').html('');
  58. $.ajax({
  59. url: "/house/housephoto?page=0&type=picture&id="+lpid+'&type_id='+album_id,
  60. type: "get",
  61. dataType: "json",
  62. success: function(data) {
  63. if(data.code == 200){
  64. $.each(data.data, function (key,val) {
  65. _html+='<li class="swiper-slide" data-id="'+album_id+'" house-id="'+lpid+'" data-type="picture" data-id="'+key+'" data-url="'+val.img+'">';
  66. _html+='<a href="javascript:;"><img src="'+val.img+'" alt=""></a>';
  67. _html+='</li>';
  68. });
  69. $('.tulist .tulist_main ul').html(_html);
  70. thisLi = $('.tulist_main li'); // 小图选择器
  71. var mySwiper = new Swiper('.tulist_main',{
  72. slidesPerView :'auto',
  73. slideToClickedSlide:true,
  74. autoplayDisableOnInteraction:false,
  75. onInit: function(swiper){
  76. //Swiper初始化了
  77. minlength = swiper.imagesToLoad.length;
  78. ImgShow(swiper.activeIndex);
  79. },
  80. })
  81. // 左切换按钮
  82. $('.lpalbumBox_l .prev-btn').on('click',function(){
  83. (minindex == 0) ? minindex = 0 : minindex--;
  84. ImgShow(minindex)
  85. if(minlength > 5 && minindex <= minlength-1 ){ //其中 12 为小图一排能显示12张图
  86. mySwiper.setWrapperTransition(800); //设定过渡的时间
  87. mySwiper.setWrapperTranslate('-'+minindex*152); //小图滑动,96为图片一次滑动的距离
  88. }
  89. // console.log(minindex)
  90. })
  91. //右切换按钮
  92. $('.lpalbumBox_l .next-btn').on('click',function(){
  93. (minindex == minlength-1) ? minindex = minlength-1 : minindex++;
  94. ImgShow(minindex)
  95. if(minlength > 5 && minindex <= minlength-5 ){ //其中 12 为小图一排能显示12张图
  96. mySwiper.setWrapperTransition(800); //设定过渡的时间
  97. mySwiper.setWrapperTranslate('-'+minindex*152); //小图滑动,96为图片一次滑动的距离
  98. }
  99. })
  100. //小图点击事件
  101. $('body .tulist_main').on('click','li',function(){
  102. var thit = $(this);
  103. minindex = thit.index();
  104. ImgShow(minindex)
  105. })
  106. $('.tulist_main li[data-id="'+urlid+'"]').click();
  107. mySwiper.setWrapperTranslate('-'+urlid*152); //小图滑动,96为图片一次滑动的距离
  108. // 获取图片地址并显示图片
  109. function ImgShow(index){
  110. var URL = thisLi.eq(index).attr('data-url');
  111. $('.list_length em').html((index+1))
  112. $('.showimg_center .img_c em img').attr('src',URL);
  113. $('.showimg_center .img_c').attr('data-index',index);
  114. $('.showimg_center .img_c').attr('data-id',album_id);
  115. $('.showimg_center .img_c').attr('house-id',lpid);
  116. $('.showimg_center .img_c').attr('data-type',typeName);
  117. thisLi.eq(index).addClass('on').siblings().removeClass('on');
  118. }
  119. }
  120. }
  121. });
  122. }else{
  123. that.addClass('on').siblings().removeClass('on');
  124. var _html="";
  125. $('.img_c_cin').html('播放视频');
  126. $('.showimg_center .y_v3videoBox').show();
  127. // 初始化变量并赋值
  128. var minindex = 0; // 小图所在的下标
  129. var minlength = 0; // 小图所有的总数
  130. // 以三行 unbind 解除绑定事件,是为了多次点导航时,执行次的原因
  131. $('.lpalbumBox_l .prev-btn').unbind();
  132. $('.lpalbumBox_l .next-btn').unbind();
  133. $('.tulist .tulist_main ul li').unbind();
  134. $('.tulist_main ul').html('');
  135. _html+='<li class="swiper-slide" data-id="0" house-id="'+lpid+'" data-type="picture" data-id="0" data-url="'+videoImg+'">';
  136. _html+='<a href="javascript:;"><img src="'+videoImg+'" alt=""></a>';
  137. _html+='</li>';
  138. $('.tulist .tulist_main ul').html(_html);
  139. thisLi = $('.tulist_main li'); // 小图选择器
  140. var mySwiper = new Swiper('.tulist_main',{
  141. slidesPerView :'auto',
  142. slideToClickedSlide:true,
  143. autoplayDisableOnInteraction:false,
  144. onInit: function(swiper){
  145. //Swiper初始化了
  146. minlength = swiper.imagesToLoad.length;
  147. ImgShow(swiper.activeIndex);
  148. },
  149. })
  150. // 左切换按钮
  151. $('.lpalbumBox_l .prev-btn').on('click',function(){
  152. (minindex == 0) ? minindex = 0 : minindex--;
  153. ImgShow(minindex)
  154. if(minlength > 5 && minindex <= minlength-1 ){ //其中 12 为小图一排能显示12张图
  155. mySwiper.setWrapperTransition(800); //设定过渡的时间
  156. mySwiper.setWrapperTranslate('-'+minindex*148); //小图滑动,96为图片一次滑动的距离
  157. }
  158. // console.log(minindex)
  159. })
  160. //右切换按钮
  161. $('.lpalbumBox_l .next-btn').on('click',function(){
  162. (minindex == minlength-1) ? minindex = minlength-1 : minindex++;
  163. ImgShow(minindex)
  164. if(minlength > 5 && minindex <= minlength-5 ){ //其中 12 为小图一排能显示12张图
  165. mySwiper.setWrapperTransition(800); //设定过渡的时间
  166. mySwiper.setWrapperTranslate('-'+minindex*148); //小图滑动,96为图片一次滑动的距离
  167. }
  168. })
  169. //小图点击事件
  170. $('body .tulist_main').on('click','li',function(){
  171. var thit = $(this);
  172. minindex = thit.index();
  173. ImgShow(minindex)
  174. })
  175. $('.tulist_main li[data-id="'+urlid+'"]').click();
  176. mySwiper.setWrapperTranslate('-'+urlid*148); //小图滑动,96为图片一次滑动的距离
  177. // 获取图片地址并显示图片
  178. function ImgShow(index){
  179. var URL = thisLi.eq(index).attr('data-url');
  180. $('.list_length em').html((index+1))
  181. $('.showimg_center .img_c em img').attr('src',URL);
  182. $('.showimg_center .img_c').attr('data-index',index);
  183. $('.showimg_center .img_c').attr('data-id',album_id);
  184. $('.showimg_center .img_c').attr('house-id',lpid);
  185. $('.showimg_center .img_c').attr('data-type',typeName);
  186. thisLi.eq(index).addClass('on').siblings().removeClass('on');
  187. }
  188. }
  189. })
  190. if (objUrl.album_id!=0) {
  191. $('.lpalbumBox_rNav a[album-id="'+objUrl.album_id+'"]').click();
  192. }else{
  193. $('.lpalbumBox_rNav a').eq(0).click();
  194. }
  195. var randomX = 100;
  196. var randomY = 243;
  197. var randvalue = parseInt(Math.random() * (randomX - randomY + 1) + randomY);
  198. $('.bin_f_text p.kt span').html(randvalue);
  199. })
  200. $(function(){
  201. /*----------------------------------图片放大特效浏览--------------------------------------------*/
  202. // 关闭按钮
  203. $('.weffects-cls').on('click',function(){
  204. $('.weffects').hide();
  205. })
  206. // 大图触发
  207. var oindex = 0;
  208. $('body').on('click','.wwlargeimg',function(){
  209. $('.weffects').show();
  210. var that = $(this);
  211. var otype = that.attr('data-id');
  212. var oid = that.attr('house-id');
  213. var oty = that.attr('data-type');
  214. var nav = '';
  215. oindex = 0;
  216. if(that.attr('data-index') != undefined && that.attr('data-index') != 'undefined'){
  217. oindex = that.attr('data-index');
  218. }
  219. if (oty=='picture') {
  220. $.ajax({
  221. type: "post",
  222. url: '/public/gethouseablum',
  223. data: {type:oty,id:oid,type_id:otype},
  224. dataType: "json",
  225. success: function(data){
  226. if(data.code == 200){
  227. // 遍历导航
  228. if ($('body .y_v3videoBox').length>0) {
  229. nav +='<a data-type="videoUrl" house-id="'+oid+'" data-id="0" href="javascript:void(0);">视频(1)</a>'
  230. }
  231. $.each(data.data.nav,function(k,v){
  232. nav += '<a house-id="'+oid+'" data-type="picture" data-id="'+v.type_id+'" href="javascript:void(0);">'+v.name+'</a>';
  233. })
  234. $('.weffects-list-nav').html('');
  235. $('.weffects-list-nav').append(nav);
  236. }
  237. $('.weffects-list-nav a[data-id="'+otype+'"]').click();
  238. }
  239. });
  240. }else if(oty=='videoUrl'){
  241. $.ajax({
  242. type: "post",
  243. url: '/public/gethouseablum',
  244. data: {type:'picture',id:oid,type_id:otype},
  245. dataType: "json",
  246. success: function(data){
  247. if(data.code == 200){
  248. // 遍历导航
  249. if ($('body .y_v3videoBox').length>0) {
  250. nav +='<a data-type="videoUrl" house-id="'+oid+'" data-id="0" href="javascript:void(0);">视频(1)</a>'
  251. };
  252. $.each(data.data.nav,function(k,v){
  253. nav += '<a house-id="'+oid+'" data-type="picture" data-id="'+v.type_id+'" href="javascript:void(0);">'+v.name+'</a>';
  254. })
  255. $('.weffects-list-nav').html('');
  256. $('.weffects-list-nav').append(nav);
  257. }
  258. $('.weffects-list-nav a[data-id="'+otype+'"]').click();
  259. }
  260. });
  261. }
  262. })
  263. // 放大导航点击
  264. $('.weffects-list-nav').on('click','a',function(){
  265. oindex = 0;
  266. var that = $(this);
  267. var otype = that.attr('data-id');
  268. var oid = that.attr('house-id');
  269. var oty = that.attr('data-type');
  270. var li = '';
  271. var v_html='';
  272. // 初始化变量并赋值
  273. var minindex = 0; // 小图所在的下标
  274. var minlength = 0; // 小图所有的总数
  275. that.addClass('on').siblings().removeClass('on');
  276. if (oty=='picture') {
  277. // 以三行 unbind 解除绑定事件,是为了多次点导航时,执行次的原因
  278. $('.weffects .prev-btn').unbind();
  279. $('.weffects .next-btn').unbind();
  280. $('.weffects-list-imgbox li').unbind();
  281. $.ajax({
  282. type: "post",
  283. url: '/public/gethouseablum',//'/js/home.json',
  284. data: {type:oty,id:oid,type_id:otype},
  285. dataType: "json",
  286. success: function(data){
  287. if(data.code == 200){
  288. // 遍历导航
  289. li += '<div class="weffects-list-img">';
  290. li += '<ul class="swiper-wrapper">';
  291. $.each(data.data.imgarr,function(k,v){
  292. li += '<li class="swiper-slide" data-url="'+v.url+'"><img src="'+v.url+'" alt=""></li>';
  293. })
  294. li += '</ul>';
  295. li+='<div class="swiper-button-prev"></div>';
  296. li+='<div class="swiper-button-next"></div>';
  297. li += '</div>';
  298. $('.weffects-list-imgbox').html('');
  299. $('.weffects-list-imgbox').append(li);
  300. }
  301. var thisLi = $('.weffects-list-imgbox li'); // 小图选择器
  302. var mySwiper = new Swiper('.weffects-list-img',{
  303. slidesPerView :'auto',
  304. spaceBetween : 8,
  305. slideToClickedSlide:true,
  306. autoplayDisableOnInteraction:false,
  307. prevButton:'.swiper-button-prev',
  308. nextButton:'.swiper-button-next',
  309. onInit: function(swiper){
  310. //Swiper初始化了
  311. minlength = swiper.imagesToLoad.length;
  312. ImgShow(swiper.activeIndex);
  313. // console.log(minlength)
  314. },
  315. })
  316. $('.weffects .prev-btn,.weffects .next-btn').show();
  317. // 左切换按钮
  318. $('.weffects .prev-btn').on('click',function(){
  319. (minindex == 0) ? minindex = 0 : minindex--;
  320. ImgShow(minindex)
  321. if(minlength > 7 && minindex <= minlength % 7 ){ //其中 12 为小图一排能显示12张图
  322. mySwiper.setWrapperTransition(800); //设定过渡的时间
  323. mySwiper.setWrapperTranslate('-'+minindex*156); //小图滑动,96为图片一次滑动的距离
  324. }
  325. // console.log(minindex)
  326. })
  327. //右切换按钮
  328. $('.weffects .next-btn').on('click',function(){
  329. (minindex == minlength-1) ? minindex = minlength-1 : minindex++;
  330. ImgShow(minindex)
  331. if(minlength > 7 && minindex <= minlength-7 ){ //其中 12 为小图一排能显示12张图
  332. mySwiper.setWrapperTransition(800); //设定过渡的时间
  333. mySwiper.setWrapperTranslate('-'+minindex*156); //小图滑动,96为图片一次滑动的距离
  334. }
  335. // console.log(minindex)
  336. })
  337. //小图点击事件
  338. $('.weffects-list-imgbox li').on('click',function(){
  339. var thit = $(this);
  340. minindex = thit.index();
  341. ImgShow(minindex)
  342. // console.log(minindex)
  343. })
  344. $('.weffects-list-imgbox li').eq(oindex).click();
  345. // 获取图片地址并显示图片
  346. function ImgShow(index){
  347. $('.magnify-box').html('');
  348. var URL = thisLi.eq(index).attr('data-url');
  349. // $('.magnify-box img').attr('src',URL);
  350. $('.magnify-box').html('<img src="'+URL+'">');
  351. thisLi.eq(index).addClass('in').siblings().removeClass('in');
  352. }
  353. }
  354. });
  355. }else if(oty=='videoUrl'){
  356. // 遍历导航
  357. li += '<div class="weffects-list-img">';
  358. li += '<ul class="swiper-wrapper">';
  359. li += '<li class="swiper-slide" data-url="'+videoImg+'"><img src="'+videoImg+'" alt=""></li>';
  360. li += '</ul>';
  361. li+='<div class="swiper-button-prev"></div>';
  362. li+='<div class="swiper-button-next"></div>';
  363. li += '</div>';
  364. $('.weffects-list-imgbox').html('');
  365. $('.weffects-list-imgbox').html(li);
  366. var thisLi = $('.weffects-list-imgbox li'); // 小图选择器
  367. var mySwiper = new Swiper('.weffects-list-img',{
  368. slidesPerView :'auto',
  369. spaceBetween : 8,
  370. slideToClickedSlide:true,
  371. autoplayDisableOnInteraction:false,
  372. prevButton:'.swiper-button-prev',
  373. nextButton:'.swiper-button-next',
  374. onInit: function(swiper){
  375. //Swiper初始化了
  376. minlength = swiper.imagesToLoad.length;
  377. ImgShow(swiper.activeIndex);
  378. // console.log(minlength)
  379. },
  380. })
  381. $('.weffects .prev-btn,.weffects .next-btn').hide();
  382. // 左切换按钮
  383. $('.weffects .prev-btn').on('click',function(){
  384. (minindex == 0) ? minindex = 0 : minindex--;
  385. ImgShow(minindex)
  386. if(minlength > 7 && minindex <= minlength % 7 ){ //其中 12 为小图一排能显示12张图
  387. mySwiper.setWrapperTransition(800); //设定过渡的时间
  388. mySwiper.setWrapperTranslate('-'+minindex*156); //小图滑动,96为图片一次滑动的距离
  389. }
  390. // console.log(minindex)
  391. })
  392. //右切换按钮
  393. $('.weffects .next-btn').on('click',function(){
  394. (minindex == minlength-1) ? minindex = minlength-1 : minindex++;
  395. ImgShow(minindex)
  396. if(minlength > 7 && minindex <= minlength-7 ){ //其中 12 为小图一排能显示12张图
  397. mySwiper.setWrapperTransition(800); //设定过渡的时间
  398. mySwiper.setWrapperTranslate('-'+minindex*156); //小图滑动,96为图片一次滑动的距离
  399. }
  400. // console.log(minindex)
  401. })
  402. //小图点击事件
  403. $('.weffects-list-imgbox li').on('click',function(){
  404. var thit = $(this);
  405. minindex = thit.index();
  406. ImgShow(minindex)
  407. })
  408. // $('.weffects-list-imgbox li').eq(oindex).click();
  409. // 获取图片地址并显示图片
  410. function ImgShow(index){
  411. $('.magnify-box').html('');
  412. var URL = thisLi.eq(index).attr('data-url');
  413. thisLi.eq(index).addClass('in').siblings().removeClass('in');
  414. v_html+='<div class="vidplay">';
  415. v_html+='<p><img src="'+URL+'" alt=""></p>';
  416. v_html+='<i><img src="/image/zuo14.png" alt=""></i>';
  417. v_html+='<video class="pause" preload controls src="'+videoR+'"></video>';
  418. v_html+='</div>';
  419. $('.magnify-box').html(v_html);
  420. }
  421. }
  422. })
  423. /*----------------------------------图片放大特效浏览end--------------------------------------------*/
  424. $('body').on('click','.vidplay',function(){
  425. if ($(this).find('video').hasClass('pause')) {
  426. $(this).find('p').hide();
  427. $(this).find('i').hide();
  428. $(this).find('video').trigger("play");
  429. $(this).find('video').removeClass('pause');
  430. $(this).find('video').addClass('play');
  431. } else {
  432. $(this).find('video').trigger("pause");
  433. $(this).find('video').removeClass('play');
  434. $(this).find('video').addClass('pause');
  435. }
  436. })
  437. })