前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >为 butterfly 主题的 twikoo 添加图片点击放大功能

为 butterfly 主题的 twikoo 添加图片点击放大功能

作者头像
Rikka
发布2022-01-20 10:10:07
1K0
发布2022-01-20 10:10:07
举报
文章被收录于专栏:rikkarikka

只需将 twikoo.pug 中对应的代码修改如下 (直接抄自 main.js)

代码语言:javascript
复制
twikoo.init(Object.assign({
  el: '#twikoo-wrap',
  envId: '!{theme.twikoo.envId}',
  region: '!{theme.twikoo.region}',
  onCommentLoaded: function () {
    if(typeof window.mediumZoom!='undefined'){
      const zoomComment = mediumZoom(document.querySelectorAll('.tk-content :not(a)>img'))
      zoomComment.on('open', e => {
        const photoBg = document.documentElement.getAttribute('data-theme') === 'dark' ? '#121212' : '#fff'
        zoomComment.update({
          background: photoBg
        })
      })
    }
    if(GLOBAL_CONFIG.lightbox === 'fancybox'){
        const addFancybox = function (ele) {
          const runFancybox = (ele) => {
            ele.each(function (i, o) {
              const $this = $(o)
              const lazyloadSrc = $this.attr('data-lazy-src') || $this.attr('src')
              const dataCaption = $this.attr('alt') || ''
              $this.wrap(`<a href="${lazyloadSrc}" data-fancybox="group" data-caption="${dataCaption}" class="fancybox"></a>`)
            })

            $().fancybox({
              selector: '[data-fancybox]',
              loop: true,
              transitionEffect: 'slide',
              protect: true,
              buttons: ['slideShow', 'fullScreen', 'thumbs', 'close'],
              hash: false
            })
          }

          if (typeof $.fancybox === 'undefined') {
            $('head').append(`<link rel="stylesheet" type="text/css" href="${GLOBAL_CONFIG.source.fancybox.css}">`)
            $.getScript(`${GLOBAL_CONFIG.source.fancybox.js}`, function () {
              runFancybox($(ele))
            })
          } else {
            runFancybox($(ele))
          }
        }
      addFancybox(document.querySelectorAll('.tk-content :not(a)>img'))
    }
  }
}, !{JSON.stringify(theme.twikoo.option)}))
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-07-16,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档