图片浏览逻辑优化
This commit is contained in:
parent
a02e8a0a1b
commit
c39fcbc894
@ -1,7 +1,7 @@
|
|||||||
<nav id="mobile-nav">
|
<nav id="mobile-nav">
|
||||||
<div class="overlay js-overlay" ></div>
|
<div class="overlay js-overlay" ></div>
|
||||||
<div class="btnctn js-mobile-btnctn">
|
<div class="btnctn js-mobile-btnctn">
|
||||||
<div class="slider-trigger list" @click="openSlider($event, 'innerArchive')"><i class="icon icon-sort"></i></div>
|
<div class="slider-trigger list" @click="openSlider($event, 'innerArchive')"><i class="icon icon-sort"></i></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="intrude-less">
|
<div class="intrude-less">
|
||||||
<header id="header" class="inner">
|
<header id="header" class="inner">
|
||||||
@ -34,5 +34,5 @@
|
|||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
</div>
|
</div>
|
||||||
<div class="mobile-mask" style="display:none" q-show="isShow"></div>
|
<div class="mobile-mask" style="display:none" v-show="isShow"></div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|||||||
@ -58,30 +58,6 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<ul class="search-ul">
|
<ul class="search-ul">
|
||||||
<p v-if="jsonFail" style="padding: 20px; font-size: 12px;">
|
|
||||||
缺失模块。<br/>1、请确保node版本大于6.2<br/>2、在博客根目录(注意不是yilia根目录)执行以下命令:<br/> npm i hexo-generator-json-content --save<br/><br/>
|
|
||||||
3、在根目录_config.yml里添加配置:
|
|
||||||
<pre style="font-size: 12px;" v-if="jsonFail">
|
|
||||||
jsonContent:
|
|
||||||
meta: false
|
|
||||||
pages: false
|
|
||||||
posts:
|
|
||||||
title: true
|
|
||||||
date: true
|
|
||||||
path: true
|
|
||||||
text: false
|
|
||||||
raw: false
|
|
||||||
content: false
|
|
||||||
slug: false
|
|
||||||
updated: false
|
|
||||||
comments: false
|
|
||||||
link: false
|
|
||||||
permalink: false
|
|
||||||
excerpt: false
|
|
||||||
categories: false
|
|
||||||
tags: true
|
|
||||||
</pre>
|
|
||||||
</p>
|
|
||||||
<li class="search-li" v-for="item in items" v-show="!item.isHide">
|
<li class="search-li" v-for="item in items" v-show="!item.isHide">
|
||||||
<a :href="item.path|urlformat" class="search-title"><i class="icon-quo-left icon"></i>
|
<a :href="item.path|urlformat" class="search-title"><i class="icon-quo-left icon"></i>
|
||||||
<span v-text="item.title"></span>
|
<span v-text="item.title"></span>
|
||||||
|
|||||||
@ -24,7 +24,6 @@ new Vue({
|
|||||||
innerArchive: false,
|
innerArchive: false,
|
||||||
friends: false,
|
friends: false,
|
||||||
aboutme: false,
|
aboutme: false,
|
||||||
jsonFail: false,
|
|
||||||
showTags: false,
|
showTags: false,
|
||||||
showCategories: false,
|
showCategories: false,
|
||||||
search: null,
|
search: null,
|
||||||
@ -105,7 +104,7 @@ new Vue({
|
|||||||
.then((res)=>{
|
.then((res)=>{
|
||||||
this.items = res.data
|
this.items = res.data
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
this.jsonFail = true
|
console.warn('加载文章列表失败')
|
||||||
})
|
})
|
||||||
this.showMessage(welcomeMessage(), 6000)
|
this.showMessage(welcomeMessage(), 6000)
|
||||||
document.addEventListener('copy', () => {
|
document.addEventListener('copy', () => {
|
||||||
|
|||||||
@ -7,36 +7,36 @@ import Util from './util'
|
|||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
let pswpElement = document.querySelectorAll('.pswp')[0]
|
let pswpElement = document.querySelectorAll('.pswp')[0]
|
||||||
let $imgArr = document.querySelectorAll('.article-entry img:not(.reward-img)')
|
let imgArr = document.querySelectorAll('.article-entry img:not(.reward-img)')
|
||||||
let getThumbBoundsFn = function(index) {
|
let getThumbBoundsFn = function(target) {
|
||||||
var thumbnail = document.querySelectorAll('.article-entry img:not(.reward-img)')[index]
|
return function(index) { // index是当前点击的图片在相册中的索引值
|
||||||
var pageYScroll = window.pageYOffset || document.documentElement.scrollTop
|
var pageYScroll = window.pageYOffset || document.documentElement.scrollTop
|
||||||
var rect = thumbnail.getBoundingClientRect()
|
var rect = target.getBoundingClientRect()
|
||||||
return {x:rect.left, y:rect.top + pageYScroll, w:rect.width}
|
return {x:rect.left, y:rect.top + pageYScroll, w:rect.width}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Array.prototype.forEach.call($imgArr, ($em, i) => {
|
const items = Array.prototype.map.call(imgArr, em => {
|
||||||
$em.addEventListener('click', function(){
|
let src = em.getAttribute('data-target') || em.getAttribute('src')
|
||||||
|
let title = em.getAttribute('alt')
|
||||||
|
// 获得原图尺寸
|
||||||
|
const image = new Image()
|
||||||
|
image.src = src
|
||||||
|
return {
|
||||||
|
msrc: src, // 缩略图的地址(在动画过程中显示的是缩略图, 这里暂且用相同的地址了)
|
||||||
|
src,
|
||||||
|
w: image.width || em.width,
|
||||||
|
h: image.height || em.height,
|
||||||
|
title
|
||||||
|
}
|
||||||
|
})
|
||||||
|
Array.prototype.forEach.call(imgArr, (em, index) => {
|
||||||
|
em.addEventListener('click', function(e){
|
||||||
// slider展开状态
|
// slider展开状态
|
||||||
if (document.querySelector('.left-col.show')) return
|
if (document.querySelector('.left-col.show')) return
|
||||||
let items = []
|
|
||||||
Array.prototype.forEach.call($imgArr, ($em2, i2) => {
|
|
||||||
let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
|
|
||||||
let title = $em2.getAttribute('alt')
|
|
||||||
// 获得原图尺寸
|
|
||||||
const image = new Image()
|
|
||||||
image.src = src
|
|
||||||
items.push({
|
|
||||||
msrc: src, // 缩略图的地址(在动画过程中显示的是缩略图, 这里暂且用相同的地址了)
|
|
||||||
src,
|
|
||||||
w: image.width || $em2.width,
|
|
||||||
h: image.height || $em2.height,
|
|
||||||
title
|
|
||||||
})
|
|
||||||
})
|
|
||||||
var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
|
var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
|
||||||
index: parseInt(i),
|
index,
|
||||||
bgOpacity: 0.8,
|
bgOpacity: 0.8,
|
||||||
getThumbBoundsFn
|
getThumbBoundsFn: getThumbBoundsFn(e.target)
|
||||||
})
|
})
|
||||||
gallery.init()
|
gallery.init()
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user