show_picture.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. $(document).ready(function(){
  2. //获取锚点即当前图片id
  3. var picid = location.hash;
  4. picid = picid.substring(1);
  5. if(isNaN(picid) || picid=='' || picid==null) {
  6. picid = 1;
  7. }
  8. picid = parseInt(picid);
  9. //图集图片总数
  10. var totalnum = $("#pictureurls li").length;
  11. //如果当前图片id大于图片数,显示第一张图片
  12. if(picid > totalnum || picid < 1) {
  13. picid = 1;
  14. next_picid = 1; //下一张图片id
  15. } else {
  16. next_picid = picid + 1;
  17. }
  18. url = $("#pictureurls li:nth-child("+picid+") img").attr("rel");
  19. $("#big-pic").html("<img src='"+url+"' onload='loadpic("+next_picid+")'>");
  20. $('#big-pic img').LoadImage(true, 890, 650,$("#load_pic").attr('rel'));
  21. $("#picnum").html("("+picid+"/"+totalnum+")");
  22. $("#picinfo").html($("#pictureurls li:nth-child("+picid+") img").attr("alt"));
  23. $("#pictureurls li").click(function(){
  24. i = $(this).index() + 1;
  25. showpic(i);
  26. });
  27. //加载时图片滚动到中间
  28. var _w = $('.cont li').width()*$('.cont li').length;
  29. if(picid>2) {
  30. movestep = picid - 3;
  31. } else {
  32. movestep = 0;
  33. }
  34. $(".cont ul").css({"left":-+$('.cont li').width()*movestep});
  35. //点击图片滚动
  36. $('.cont ul').width(_w);
  37. $(".cont li").click( function () {
  38. if($(this).index()>2){
  39. movestep = $(this).index() - 2;
  40. $(".cont ul").css({"left":-+$('.cont li').width()*movestep});
  41. }
  42. });
  43. //当前缩略图添加样式
  44. $("#pictureurls li:nth-child("+picid+")").addClass("on");
  45. });
  46. $(document).keyup(function(e) {
  47. var currKey=0,e=e||event;
  48. currKey=e.keyCode||e.which||e.charCode;
  49. switch(currKey) {
  50. case 37: // left
  51. showpic('pre');
  52. break;
  53. case 39: // up
  54. showpic('next');
  55. break;
  56. case 13: // enter
  57. var nextpicurl = $('#nextPicsBut').attr('href');
  58. if(nextpicurl !== '' || nextpicurl !== 'null') {
  59. window.location=nextpicurl;
  60. }
  61. break;
  62. }
  63. });
  64. function showpic(type, replay) {
  65. //隐藏重复播放div
  66. $("#endSelect").hide();
  67. //图集图片总数
  68. var totalnum = $("#pictureurls li").length;
  69. if(type=='next' || type=='pre') {
  70. //获取锚点即当前图片id
  71. var picid = location.hash;
  72. picid = picid.substring(1);
  73. if(isNaN(picid) || picid=='' || picid==null) {
  74. picid = 1;
  75. }
  76. picid = parseInt(picid);
  77. if(type=='next') {
  78. i = picid + 1;
  79. //如果是最后一张图片,指针指向第一张
  80. if(i > totalnum) {
  81. $("#endSelect").show();
  82. i=1;
  83. next_picid=1;
  84. //重新播放
  85. if(replay!=1) {
  86. return false;
  87. } else {
  88. $("#endSelect").hide();
  89. }
  90. } else {
  91. next_picid = parseInt(i) + 1;
  92. }
  93. } else if (type=='pre') {
  94. i = picid - 1;
  95. //如果是第一张图片,指针指向最后一张
  96. if(i < 1) {
  97. i=totalnum;
  98. next_picid = totalnum;
  99. } else {
  100. next_picid = parseInt(i) - 1;
  101. }
  102. }
  103. url = $("#pictureurls li:nth-child("+i+") img").attr("rel");
  104. $("#big-pic").html("<img src='"+url+"' onload='loadpic("+next_picid+")'>");
  105. $('#big-pic img').LoadImage(true, 890, 650,$("#load_pic").attr('rel'));
  106. $("#picnum").html("("+i+"/"+totalnum+")");
  107. $("#picinfo").html($("#pictureurls li:nth-child("+i+") img").attr("alt"));
  108. //更新锚点
  109. location.hash = i;
  110. type = i;
  111. //点击图片滚动
  112. var _w = $('.cont li').width()*$('.cont li').length;
  113. if(i>2) {
  114. movestep = i - 3;
  115. } else {
  116. movestep = 0;
  117. }
  118. $(".cont ul").css({"left":-+$('.cont li').width()*movestep});
  119. } else if(type=='big') {
  120. //获取锚点即当前图片id
  121. var picid = location.hash;
  122. picid = picid.substring(1);
  123. if(isNaN(picid) || picid=='' || picid==null) {
  124. picid = 1;
  125. }
  126. picid = parseInt(picid);
  127. url = $("#pictureurls li:nth-child("+picid+") img").attr("rel");
  128. window.open(url);
  129. } else {
  130. url = $("#pictureurls li:nth-child("+type+") img").attr("rel");
  131. $("#big-pic").html("<img src='"+url+"'>");
  132. $('#big-pic img').LoadImage(true, 890, 650,$("#load_pic").attr('rel'));
  133. $("#picnum").html("("+type+"/"+totalnum+")");
  134. $("#picinfo").html($("#pictureurls li:nth-child("+type+") img").attr("alt"));
  135. location.hash = type;
  136. }
  137. $("#pictureurls li").each(function(i){
  138. j = i+1;
  139. if(j==type) {
  140. $("#pictureurls li:nth-child("+j+")").addClass("on");
  141. } else {
  142. $("#pictureurls li:nth-child("+j+")").removeClass();
  143. }
  144. });
  145. }
  146. //预加载图片
  147. function loadpic(id) {
  148. url = $("#pictureurls li:nth-child("+id+") img").attr("rel");
  149. $("#load_pic").html("<img src='"+url+"'>");
  150. }