photodetails.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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/Mediaonefive/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);
  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);
  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);
  95. })
  96. // 底部标签栏
  97. $(".tabbar li").on("click", function () {
  98. if ($(this).index() === 0) {
  99. $(location).attr("href", 'https://www.bibidd.com/bibidd_testtest');
  100. }else if ($(this).index() === 1) {
  101. $(location).attr("href", 'photo.html');
  102. }
  103. });
  104. // 标签检索图片
  105. $('.label').on('click', function(){
  106. $('.videopage').show();
  107. $('.labelpage').hide();
  108. $('h2').text($(this).text());
  109. })
  110. // 注册/登录
  111. $('.accountRight').on('click', function() {
  112. $('.loginBox').show();
  113. })
  114. $('.guanbi').on('click', function() {
  115. $('.loginBox').hide();
  116. })
  117. // 查看我的收藏
  118. $('#register').on('click', function() {
  119. if($(this).text()==='My Collection') {
  120. $(location).attr('href', 'collection.html');
  121. }else {
  122. // 注册
  123. $(location).attr('href', 'register.html');
  124. }
  125. $('.loginBox').hide();
  126. })
  127. // 登录/退出登录
  128. $('#login').on('click', function() {
  129. if($(this).text()==='Log out') {
  130. // 退出登录
  131. localStorage.removeItem('uid');
  132. location.reload();
  133. }else {
  134. // 登录
  135. $(location).attr('href', 'blogin.html');
  136. }
  137. $('.loginBox').hide();
  138. })
  139. // 判断屏幕滚动高度是否超过1屏
  140. $(window).scroll(function() {
  141. var scrollT = $(document).scrollTop();
  142. var offsetT = $('.main').offset().top;
  143. if(scrollT >= offsetT) {
  144. $('.backToTop').show();
  145. }else {
  146. $('.backToTop').hide();
  147. }
  148. })
  149. // 返回顶部
  150. $('.backToTop').on('click', function() {
  151. $('html, body').animate({
  152. scrollTop:0
  153. }, 500);
  154. })
  155. // 判断当前是否可以进行收藏相关交互
  156. var collectionChange = false;
  157. // 判断该图片是否被收藏接口
  158. function collectionData() {
  159. $.ajax({
  160. type:'post',
  161. url:'https://www.bibidd.com/bibidd/Mediaonefive/yn_shoucang',
  162. dataType: "json",
  163. data: {
  164. type:'img',
  165. cid:imgid,
  166. uid:uid
  167. },
  168. success: function (res) {
  169. },
  170. complete:function(res) {
  171. let collectionData = res.responseJSON.message;
  172. collectionChange = true;
  173. if(collectionData === 'ok') {
  174. // 已经被收藏
  175. $('.collection img').attr('src','/Public/bibidd/images/xingsel.png');
  176. // $('.collection').find("p").eq(0).text('Favorite');
  177. collectionStatus = true;
  178. }else {
  179. // 没被收藏
  180. $('.collection img').attr('src','/Public/bibidd/images/xing.png');
  181. // $('.collection').find("p").eq(0).text('Not collected');
  182. collectionStatus = false;
  183. }
  184. }
  185. })
  186. }
  187. if(uid){
  188. collectionData();
  189. $('#register').text('My Collection');
  190. $('#login').text('Log out');
  191. $("#login").css("backgroundColor", "#D6565A");
  192. }else{
  193. // $('.collection').find("p").eq(0).text('Not collected');
  194. $('#register').text('Sign up');
  195. $('#login').text('Login');
  196. $("#login").css("backgroundColor", "#CE5C2A");
  197. }
  198. // 点赞
  199. var fabulousStatus = true;
  200. $('.fabulous').on('click', function() {
  201. $('.collection img').attr('src','/Public/bibidd/images/load.png');
  202. setTimeout(() => {
  203. $('.collection img').attr('src','/Public/bibidd/images/zan.png');
  204. $.ajax({
  205. type:'post',
  206. url:'https://www.bibidd.com/bibidd/Mediaonefive/dianzan_img_video',
  207. dataType: "json",
  208. data: {
  209. type:'img',
  210. cid:imgid,
  211. uid:uid
  212. },
  213. success: function (res) {
  214. let fabulous = $('.fabulous').find("p").eq(0).text();
  215. $('.fabulous').find("p").eq(0).text(Number(fabulous) + 1);
  216. }
  217. })
  218. }, 2000);
  219. })
  220. // 收藏
  221. $('.collection').on('click', function() {
  222. if(uid){
  223. if(collectionStatus) {
  224. $('.collection img').attr('src','/Public/bibidd/images/xing.png');
  225. // $('.collection').find("p").eq(0).text('Not collected');
  226. collectionclose();
  227. }else {
  228. $('.collection img').attr('src','/Public/bibidd/images/xingsel.png');
  229. // $('.collection').find("p").eq(0).text('Favorite');
  230. collectionAdd();
  231. }
  232. }else{
  233. // 弹窗提示去登录
  234. $('.loginBox').show();
  235. }
  236. })
  237. // 添加收藏
  238. function collectionAdd() {
  239. $.ajax({
  240. type:'post',
  241. url:'https://www.bibidd.com/bibidd/Mediaonefive/add_to_shoucang',
  242. dataType: "json",
  243. data: {
  244. type:'img',
  245. cid:imgid,
  246. uid:uid
  247. },
  248. success: function (res) {
  249. },
  250. complete:function(res) {
  251. collectionChange = true;
  252. let collectionData = res.responseJSON.message;
  253. if(collectionData === 'ok') {
  254. // 已经被收藏
  255. $('.collection img').attr('src','/Public/bibidd/images/xingsel.png');
  256. // $('.collection').find("p").eq(0).text('Favorite');
  257. collectionStatus = true;
  258. }else {
  259. $('.collection img').attr('src','/Public/bibidd/images/xing.png');
  260. // $('.collection').find("p").eq(0).text('Not collected');
  261. collectionStatus = false;
  262. tip('Please try again later');
  263. }
  264. }
  265. })
  266. }
  267. // 取消收藏
  268. function collectionclose() {
  269. $.ajax({
  270. type:'post',
  271. url:'https://www.bibidd.com/bibidd/Mediaonefive/quxiao_shoucang',
  272. dataType: "json",
  273. data: {
  274. type:'img',
  275. cid:imgid,
  276. uid:uid
  277. },
  278. success: function (res) {
  279. },
  280. complete:function(res) {
  281. let collectionData = res.responseJSON.message;
  282. if(collectionData === 'ok') {
  283. // 已经取消收藏
  284. $('.collection img').attr('src','/Public/bibidd/images/xing.png');
  285. // $('.collection').find("p").eq(0).text('Not collected');
  286. collectionStatus = false;
  287. }else {
  288. $('.collection img').attr('src','/Public/bibidd/images/xingsel.png');
  289. // $('.collection').find("p").eq(0).text('Favorite');
  290. collectionStatus = true;
  291. tip('Please try again later');
  292. }
  293. }
  294. })
  295. }
  296. function tip(text) {
  297. $('#tip').show();
  298. $('.tiptext').text(text);
  299. setTimeout(() => {
  300. $('#tip').hide();
  301. }, 1000);
  302. }
  303. $('.guanbiBigImg img').on('click',function() {
  304. $('.bigImgWrap').hide();
  305. })
  306. $('.clearTextImg').on('click', function() {
  307. $('.searchInput').val('');
  308. })
  309. })