album.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. $(function(){
  2. $('#yii-debug-toolbar').hide();
  3. // 相册ajax
  4. function index_lp (){
  5. var html = '';
  6. $('.m_album_r_lsit').html('')
  7. $.ajax({
  8. url: "/house/albumlist",
  9. data:{hid:hid,album_id:album_id},
  10. type: "POST",
  11. dataType: "json",
  12. success: function(data) {//请求成功完成后要执行的方法
  13. if (data.code == 200) {
  14. $.each(data.data, function (i, data) {
  15. html+='<div class="m_lsitImg" data-style="'+data.album_id+'" data-index="'+i+'"><img src="" data-lazy-src="'+data.img+'" alt=""></div>';
  16. });
  17. };
  18. $('.m_album_r_lsit').html(html);
  19. $('.m_album_r_lsit .m_lsitImg').on('click',function(){
  20. var _dataStyle = $(this).attr('data-style');
  21. var _dataIndex = $(this).attr('data-index');
  22. console.log(_dataStyle);
  23. console.log(_dataIndex);
  24. window.location='/house/pvimage/'+hid+'?album_id='+_dataStyle+'&mindex='+_dataIndex+'&hid='+hid+'';
  25. })
  26. // 图片懒加载
  27. $('.m_album_r').on('scroll resize load', function(e){
  28. var notFoundCount = 0, maxNotFound = 2, screenHeight = $(window).height();
  29. $('[data-lazy-src]').each(function()
  30. {
  31. var pos = this.getBoundingClientRect();
  32. if(pos.bottom <= 0) return true; // 如果当前图片在视野上方,继续往下查找
  33. if(pos.top >= screenHeight) return (notFoundCount++) < maxNotFound; // 如果连续超过 maxNotFound 张图片都在视野下方,停止查找,注意只有从上到下的图片布局才能这样判断
  34. var src = this.dataset.lazySrc;
  35. if(!src) return;
  36. if(this.nodeName === 'IMG') this.src = src;
  37. else this.style.backgroundImage = 'url(' + src + ')';
  38. this.removeAttribute('data-lazy-src');
  39. });
  40. });
  41. $('.m_album_r').scroll();
  42. }
  43. });
  44. }
  45. $('.m_album_r_lsit .m_lsitImg').on('click',function(){
  46. var _dataStyle = $(this).attr('data-style');
  47. var _dataIndex = $(this).attr('data-index');
  48. console.log(_dataStyle);
  49. console.log(_dataIndex);
  50. window.location='/house/pvimage/'+hid+'?album_id='+_dataStyle+'&mindex='+_dataIndex+'&hid='+hid+'';
  51. })
  52. //获取url中的参数
  53. function getUrlParam(name){
  54. //构造一个含有目标参数的正则表达式对象
  55. var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  56. //匹配目标参数
  57. var r = window.location.search.substr(1).match(reg);
  58. //alert(r);
  59. //返回参数值
  60. if (r!=null) return decodeURI(r[2]);
  61. return null;
  62. }
  63. var hid = $('.m_album_l_title span').eq(0).attr('hid');
  64. var album_id = '';
  65. // URL接受参数
  66. var _albumid = getUrlParam('album_id'); //类型
  67. if(_albumid){ //是否从放大页,进入页面
  68. album_id = _albumid
  69. $('.m_album_l_title span[value="'+_albumid+'"]').attr('class','on');
  70. }else{
  71. album_id = $('.m_album_l_title span').eq(0).attr('value');
  72. $('.m_album_l_title span').eq(0).attr('class','on');
  73. }
  74. // index_lp();
  75. $('.m_album_l_title span').on('click',function(){
  76. hid = $(this).attr('hid');
  77. album_id = $(this).attr('value');
  78. $(this).attr('class','on').siblings().attr('class','')
  79. // index_lp();
  80. })
  81. var height =$(window).height() -155;
  82. $('.m_album_box').height(height);
  83. })
  84. var _dataid = $('.m_hq li.cur').attr('dataid');
  85. //demo示例六 通过id调取 底部菜单插件
  86. $('#mdemo06').navbarscroll({
  87. defaultSelect:_dataid,
  88. scrollerWidth:6,
  89. fingerClick:1,
  90. endClickScroll:function(obj){
  91. // console.log(obj.text())
  92. }
  93. });