From b7abf6a72c6be4194ba38535ed58a7761be1cae7 Mon Sep 17 00:00:00 2001 From: zhaohaihao Date: Thu, 28 Mar 2019 00:25:57 +0800 Subject: [PATCH] feat: img enlarge --- layout/_partial/scripts.ejs | 7 +++++++ source/js/fancybox-use.js | 13 +++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 source/js/fancybox-use.js diff --git a/layout/_partial/scripts.ejs b/layout/_partial/scripts.ejs index 5a83ee7..f74781a 100755 --- a/layout/_partial/scripts.ejs +++ b/layout/_partial/scripts.ejs @@ -171,3 +171,10 @@ <% (config.import.script||[]).forEach(function(item){ %> <%- item %><% }) %> <% } %> + + + + + + + diff --git a/source/js/fancybox-use.js b/source/js/fancybox-use.js new file mode 100644 index 0000000..69d5120 --- /dev/null +++ b/source/js/fancybox-use.js @@ -0,0 +1,13 @@ +// 集成fancybox, 为所有img元素添加父元素 +$("img").each(function () { + var value = $(this).attr("class"); + // 头像不进行放大 + if(value === "avatar") { + return ture; + } + + var element = document.createElement("a"); + $(element).attr("data-fancybox", "gallery"); + $(element).attr("href", $(this).attr("src")); + $(this).wrap(element); +}); \ No newline at end of file