photodetails.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. $(document).ready(function () {
  2. $('.logo').on('click', function() {
  3. window.location.href = "https://www.bibidd.com";
  4. })
  5. $('.quanpinghei').hide();
  6. // 页面传参
  7. var url = window.location.search;
  8. // 判断图片是否被收藏参数
  9. var collectionStatus;
  10. var theRequest = new Object();
  11. if (url.indexOf("?") != -1) {
  12. var str = url.substr(1);
  13. strs = str.split("&");
  14. for (var i = 0; i < strs.length; i++) {
  15. theRequest[strs[i].split("=")[0]] = unescape(
  16. decodeURIComponent(strs[i].split("=")[1])
  17. );
  18. }
  19. }
  20. var username = localStorage.getItem('username');
  21. var uid = localStorage.getItem("uid");
  22. if (uid) {
  23. $("#register").text("My Collection");
  24. $("#login").text("Log out");
  25. $("#login").css("backgroundColor", "#D6565A");
  26. } else {
  27. $("#register").text("Sign up");
  28. $("#login").text("Login");
  29. $("#login").css("backgroundColor", "#CE5C2A");
  30. }
  31. // 获取视频id
  32. var imgid = theRequest.imgid;
  33. // 获取点赞数量
  34. var fabulous = theRequest.fabulous;
  35. $('.fabulous').find("p").eq(0).text(fabulous);
  36. function getData() {
  37. $.ajax({
  38. type:'post',
  39. url:'https://www.bibidd.com/bibidd/Media/img_detail',
  40. dataType: "json",
  41. data: {
  42. imgs_id: imgid
  43. },
  44. success: function (res) {
  45. },
  46. complete:function(res) {
  47. let dataArray = res.responseJSON.data;
  48. let imgListHtml = '';
  49. $.each(dataArray, function(index, data) {
  50. // imgListHtml += '<img class="load img" src="'+data+'" alt="">';
  51. // imgListHtml += '<div class="load img" data-original="' + data + '"></div>';
  52. imgListHtml += '<p class="img"> <img data-original="' + data + '" alt=""></p>';
  53. })
  54. $('.imgList').html(imgListHtml);
  55. var loadingUrl = "/Public/bibidd/images/photoloading.png";
  56. $(".img img").lazyload({
  57. effect: "fadeIn",
  58. placeholder: loadingUrl,
  59. failurelimit: 10,
  60. });
  61. $('.loading').hide();
  62. $('.img').on('click',function() {
  63. $('.bigImgWrap').show();
  64. $('.bigImg').attr('src', dataArray[$(this).index()]);
  65. })
  66. }
  67. })
  68. }
  69. getData();
  70. $('h2').text(theRequest.name);
  71. // 热门tag分类
  72. $(".nav li").on("click", function () {
  73. const pname = $(this).find("p").eq(0).text();
  74. $(location).attr("href", "photo.html?navtag=" + pname + '?status='+1);
  75. });
  76. // 视频搜索
  77. $(".searchBtn").on("click", function () {
  78. if (!$(".searchInput").val().trim()) {
  79. // 请输入搜索关键字
  80. tip('Please enter the search content');
  81. } else {
  82. const pname = $(".searchInput").val().trim();
  83. $(location).attr("href", "photo.html?navtag=" + pname + '?status='+1);
  84. }
  85. });
  86. $(document).on('keyup', function(event) {
  87. if(event.keyCode ==13){
  88. $(".searchBtn").trigger("click");
  89. }
  90. })
  91. // 查看图片详情
  92. $('.videoContent').on('click', function() {
  93. const videoName = $(this).find('div').eq(1).text();
  94. $(location).attr("href", "bphotodetails.html?name="+videoName + '?status='+1);
  95. })
  96. // 底部标签栏
  97. // 底部标签栏
  98. $(".tabbar li").on("click", function () {
  99. if ($(this).index() === 0) {
  100. $(location).attr("href", 'https://www.bibidd.com?status='+1);
  101. }else if ($(this).index() === 1) {
  102. $(location).attr("href", 'photo.html?status='+1);
  103. }
  104. });
  105. // 标签检索图片
  106. $('.label').on('click', function(){
  107. $('.videopage').show();
  108. $('.labelpage').hide();
  109. $('h2').text($(this).text());
  110. })
  111. // 注册/登录
  112. $('.accountRight').on('click', function() {
  113. $('.loginBox').show();
  114. })
  115. $('.guanbi').on('click', function() {
  116. $('.loginBox').hide();
  117. })
  118. // 查看我的收藏
  119. $('#register').on('click', function() {
  120. if($(this).text()==='My Collection') {
  121. $(location).attr('href', 'collection.html?status='+1);
  122. }else {
  123. // 注册
  124. $(location).attr('href', 'register.html?status='+1);
  125. }
  126. $('.loginBox').hide();
  127. })
  128. // 登录/退出登录
  129. $('#login').on('click', function() {
  130. if($(this).text()==='Log out') {
  131. // 退出登录
  132. localStorage.removeItem('uid');
  133. location.reload();
  134. }else {
  135. // 登录
  136. $(location).attr('href', 'login.html?status='+1);
  137. }
  138. $('.loginBox').hide();
  139. })
  140. // 判断屏幕滚动高度是否超过1屏
  141. $(window).scroll(function() {
  142. var scrollT = $(document).scrollTop();
  143. var offsetT = $('.main').offset().top;
  144. if(scrollT >= offsetT) {
  145. $('.backToTop').show();
  146. }else {
  147. $('.backToTop').hide();
  148. }
  149. })
  150. // 返回顶部
  151. $('.backToTop').on('click', function() {
  152. $('html, body').animate({
  153. scrollTop:0
  154. }, 500);
  155. })
  156. // 判断当前是否可以进行收藏相关交互
  157. var collectionChange = false;
  158. // 判断该图片是否被收藏接口
  159. function collectionData() {
  160. $.ajax({
  161. type:'post',
  162. url:'https://www.bibidd.com/bibidd/Media/yn_shoucang',
  163. dataType: "json",
  164. data: {
  165. type:'img',
  166. cid:imgid,
  167. uid:uid
  168. },
  169. success: function (res) {
  170. },
  171. complete:function(res) {
  172. let collectionData = res.responseJSON.message;
  173. collectionChange = true;
  174. if(collectionData === 'ok') {
  175. // 已经被收藏
  176. $('.collection img').attr('src','/Public/bibidd/images/xingsel.png');
  177. $('.collection').find("p").eq(0).text('Favorite');
  178. collectionStatus = true;
  179. }else {
  180. // 没被收藏
  181. $('.collection img').attr('src','/Public/bibidd/images/xing.png');
  182. $('.collection').find("p").eq(0).text('Not collected');
  183. collectionStatus = false;
  184. }
  185. }
  186. })
  187. }
  188. if(uid){
  189. collectionData();
  190. $('#register').text('My Collection');
  191. $('#login').text('Log out');
  192. $("#login").css("backgroundColor", "#D6565A");
  193. }else{
  194. $('.collection').find("p").eq(0).text('Not collected');
  195. $('#register').text('Sign up');
  196. $('#login').text('Login');
  197. $("#login").css("backgroundColor", "#CE5C2A");
  198. }
  199. // 点赞
  200. var fabulousStatus = true;
  201. $('.fabulous').on('click', function() {
  202. $('.collection img').attr('src','/Public/bibidd/images/load.png');
  203. setTimeout(() => {
  204. $('.collection img').attr('src','/Public/bibidd/images/zan.png');
  205. $.ajax({
  206. type:'post',
  207. url:'https://www.bibidd.com/bibidd/Media/dianzan_img_video',
  208. dataType: "json",
  209. data: {
  210. type:'img',
  211. cid:imgid,
  212. uid:uid
  213. },
  214. success: function (res) {
  215. let fabulous = $('.fabulous').find("p").eq(0).text();
  216. $('.fabulous').find("p").eq(0).text(Number(fabulous) + 1);
  217. }
  218. })
  219. }, 2000);
  220. })
  221. // 收藏
  222. $('.collection').on('click', function() {
  223. if(uid){
  224. if(collectionStatus) {
  225. $('.collection img').attr('src','/Public/bibidd/images/xing.png');
  226. $('.collection').find("p").eq(0).text('Not collected');
  227. collectionclose();
  228. }else {
  229. $('.collection img').attr('src','/Public/bibidd/images/xingsel.png');
  230. $('.collection').find("p").eq(0).text('Favorite');
  231. collectionAdd();
  232. }
  233. }else{
  234. // 弹窗提示去登录
  235. $('.loginBox').show();
  236. }
  237. })
  238. // 添加收藏
  239. function collectionAdd() {
  240. $.ajax({
  241. type:'post',
  242. url:'https://www.bibidd.com/bibidd/Media/add_to_shoucang',
  243. dataType: "json",
  244. data: {
  245. type:'img',
  246. cid:imgid,
  247. uid:uid
  248. },
  249. success: function (res) {
  250. },
  251. complete:function(res) {
  252. collectionChange = true;
  253. let collectionData = res.responseJSON.message;
  254. if(collectionData === 'ok') {
  255. // 已经被收藏
  256. $('.collection img').attr('src','/Public/bibidd/images/xingsel.png');
  257. $('.collection').find("p").eq(0).text('Favorite');
  258. collectionStatus = true;
  259. }else {
  260. $('.collection img').attr('src','/Public/bibidd/images/xing.png');
  261. $('.collection').find("p").eq(0).text('Not collected');
  262. collectionStatus = false;
  263. tip('Please try again later');
  264. }
  265. }
  266. })
  267. }
  268. // 取消收藏
  269. function collectionclose() {
  270. $.ajax({
  271. type:'post',
  272. url:'https://www.bibidd.com/bibidd/Media/quxiao_shoucang',
  273. dataType: "json",
  274. data: {
  275. type:'img',
  276. cid:imgid,
  277. uid:uid
  278. },
  279. success: function (res) {
  280. },
  281. complete:function(res) {
  282. let collectionData = res.responseJSON.message;
  283. if(collectionData === 'ok') {
  284. // 已经取消收藏
  285. $('.collection img').attr('src','/Public/bibidd/images/xing.png');
  286. $('.collection').find("p").eq(0).text('Not collected');
  287. collectionStatus = false;
  288. }else {
  289. $('.collection img').attr('src','/Public/bibidd/images/xingsel.png');
  290. $('.collection').find("p").eq(0).text('Favorite');
  291. collectionStatus = true;
  292. tip('Please try again later');
  293. }
  294. }
  295. })
  296. }
  297. function tip(text) {
  298. $('#tip').show();
  299. $('.tiptext').text(text);
  300. setTimeout(() => {
  301. $('#tip').hide();
  302. }, 1000);
  303. }
  304. $('.guanbiBigImg img').on('click',function() {
  305. $('.bigImgWrap').hide();
  306. })
  307. $('.clearTextImg').on('click', function() {
  308. $('.searchInput').val('');
  309. })
  310. })