detail.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. function directory(container, flag = true) {
  2. const section = $('.bk-section')
  3. section.find('h2').each(function (index, item) {
  4. const fristTitle = 'heading-' + (index + 1);
  5. const fristTitleItem = $('<li></li>');
  6. const a = $('<a></a>')
  7. const text = flag ? (index + 1) + '、' + $(item).text() : $(item).text();
  8. a.text(text)
  9. a.attr('href', 'javascript:void(0)')
  10. a.attr('data-id', fristTitle)
  11. fristTitleItem.append(a)
  12. $(container).append(fristTitleItem)
  13. $(item).attr('id', fristTitle)
  14. if (flag) {
  15. let subTitle = $('<ul></ul>')
  16. fristTitleItem.append(subTitle)
  17. $(item).parent().nextUntil('.bk-title').each(function (i, el) {
  18. if (el.nodeName !== 'H3') return
  19. const subTitleItem = $('<li></li>')
  20. const a = $('<a></a>')
  21. a.text($(el).text())
  22. a.attr('href', 'javascript:void(0)')
  23. a.attr('data-id', fristTitle + i)
  24. subTitleItem.append(a)
  25. subTitle.append(subTitleItem)
  26. $(el).attr('id', fristTitle + i)
  27. })
  28. }
  29. })
  30. }
  31. $(function () {
  32. directory('#bk-directory-pc', true)
  33. directory('#bk-directory-mobile', false)
  34. $('.bk-directory-list').find('a').on('click', function () {
  35. const id = '#' + $(this).attr('data-id');
  36. const scrollTop = innerWidth > 768 ? $(id).offset().top - $('header').height() : $(id).offset().top - $('header').height() - $('.bk-directory').height();
  37. $("html, body").animate({
  38. scrollTop: scrollTop
  39. }, {duration: 500, easing: "swing"});
  40. return false;
  41. })
  42. $('img.scapegoat').on('click', function () {
  43. const id = $(this).attr('data-ctrid')
  44. $("html, body").animate({
  45. scrollTop: $('#' + id).offset().top
  46. }, {duration: 500, easing: "swing"});
  47. })
  48. $('.bk-literature-list i').on('click', function(){
  49. const id = $(this).parent('li').attr('id')
  50. if(!id) return
  51. const selector = '[data-ctrid=' + id + ']'
  52. $("html, body").animate({
  53. scrollTop: $(selector).eq(0).offset().top - 150
  54. }, {duration: 500, easing: "swing"});
  55. })
  56. // 视频播放
  57. $('.bk-album .bk-play').on('click', function(){
  58. const videoUrl = $(this).siblings('video').attr('src');
  59. $('#video-popup video').attr('src', videoUrl);
  60. $('#video-popup').show();
  61. })
  62. $('#video-popup .close').on('click', function(){
  63. $(this).parents('#video-popup').hide();
  64. });
  65. })