Skip to content

Commit

Permalink
feat: 懒加载优化
Browse files Browse the repository at this point in the history
  • Loading branch information
D-Sketon committed Jun 26, 2023
1 parent 6b92f7d commit cf117ea
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,6 @@ vendor:
pace: https://unpkg.com/[email protected]/pace.min.js
mermaid: https://unpkg.com/[email protected]/dist/mermaid.min.js
css:
highlight: https://cdn.jsdelivr.net/npm/typeface-source-code-pro@latest/index.min.css
highlight: https://unpkg.com/typeface-source-code-pro@1.1.13/index.css
fancybox: https://unpkg.com/@fancyapps/[email protected]/dist/jquery.fancybox.min.css
katex: https://unpkg.com/[email protected]/dist/katex.min.css
8 changes: 7 additions & 1 deletion source/css/_partial/article.styl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ $article-meta-tag
height: auto
display: block
margin: auto
opacity: 0
transition: all 0.3s ease

img.lazyloaded
opacity: 1
animation: blur 0.8s ease-in-out forwards

iframe
border: none
Expand Down Expand Up @@ -291,7 +297,7 @@ $article-meta-tag
img
display: block
opacity: 0
transition: opacity 200ms ease-out
animation: blur 0.8s ease-in-out forwards
position: absolute
left: 0
top: 0
Expand Down
1 change: 1 addition & 0 deletions source/css/_partial/friend.styl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

img.lazyloaded
opacity: 1
animation: blur 0.8s ease-in-out forwards

.friend-info-wrap
display: flex
Expand Down
3 changes: 2 additions & 1 deletion source/css/_partial/post.styl
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ $post-cover
img
display: block
opacity: 0
transition: all 0.3s ease
transition: opacity 200ms ease-out
position: absolute
left: 0
top: 0
Expand All @@ -133,6 +133,7 @@ $post-cover

img.lazyloaded
opacity: 1
animation: blur 0.3s ease-in-out forwards

.post-cover-left
@media mq-normal
Expand Down
1 change: 1 addition & 0 deletions source/css/_partial/sidebar.styl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

img.lazyloaded
opacity: 1
animation: blur 0.8s ease-in-out forwards

.sidebar-author-name
font-weight: bold
Expand Down
6 changes: 6 additions & 0 deletions source/css/_util/animation.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@keyframes blur
0%
filter: blur(10px)

to
filter: blur(0)
1 change: 1 addition & 0 deletions source/css/style.styl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@import "_variables"
@import "_util/mixin"
@import "_util/grid"
@import "_util/animation"
@import "_extend"

global-reset()
Expand Down
9 changes: 9 additions & 0 deletions source/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ const getRealPath = (pathname, desc = false) => {
};

(function ($) {
// lazysizes
const imgs = $('.article-entry img');
imgs.each(function() {
const src = $(this).attr('src');
$(this).addClass('lazyload');
$(this).removeAttr('src');
$(this).attr('data-src', src);
$(this).attr('data-sizes','auto');
})
// Share
$('body').on('click', function () {
$('.article-share-box.on').removeClass('on');
Expand Down

0 comments on commit cf117ea

Please sign in to comment.