123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- function directory(container, flag = true) {
- const section = $('.bk-section')
- section.find('h2').each(function (index, item) {
- const fristTitle = 'heading-' + (index + 1);
- const fristTitleItem = $('<li></li>');
- const a = $('<a></a>')
- const text = flag ? (index + 1) + '、' + $(item).text() : $(item).text();
- a.text(text)
- a.attr('href', 'javascript:void(0)')
- a.attr('data-id', fristTitle)
- fristTitleItem.append(a)
- $(container).append(fristTitleItem)
- $(item).attr('id', fristTitle)
- if (flag) {
- let subTitle = $('<ul></ul>')
- fristTitleItem.append(subTitle)
- $(item).parent().nextUntil('.bk-title').each(function (i, el) {
- if (el.nodeName !== 'H3') return
- const subTitleItem = $('<li></li>')
- const a = $('<a></a>')
- a.text($(el).text())
- a.attr('href', 'javascript:void(0)')
- a.attr('data-id', fristTitle + i)
- subTitleItem.append(a)
- subTitle.append(subTitleItem)
- $(el).attr('id', fristTitle + i)
- })
- }
- })
- }
- $(function () {
- directory('#bk-directory-pc', true)
- directory('#bk-directory-mobile', false)
- $('.bk-directory-list').find('a').on('click', function () {
- const id = '#' + $(this).attr('data-id');
- const scrollTop = innerWidth > 768 ? $(id).offset().top - $('header').height() : $(id).offset().top - $('header').height() - $('.bk-directory').height();
- $("html, body").animate({
- scrollTop: scrollTop
- }, {duration: 500, easing: "swing"});
- return false;
- })
- $('img.scapegoat').on('click', function () {
- const id = $(this).attr('data-ctrid')
- $("html, body").animate({
- scrollTop: $('#' + id).offset().top
- }, {duration: 500, easing: "swing"});
- })
- $('.bk-literature-list i').on('click', function(){
- const id = $(this).parent('li').attr('id')
- if(!id) return
- const selector = '[data-ctrid=' + id + ']'
- $("html, body").animate({
- scrollTop: $(selector).eq(0).offset().top - 150
- }, {duration: 500, easing: "swing"});
- })
- // 视频播放
- $('.bk-album .bk-play').on('click', function(){
- const videoUrl = $(this).siblings('video').attr('src');
- $('#video-popup video').attr('src', videoUrl);
- $('#video-popup').show();
- })
- $('#video-popup .close').on('click', function(){
- $(this).parents('#video-popup').hide();
- });
- })
|