update floating trick

This commit is contained in:
Spirit 2019-08-25 11:57:53 +08:00
parent fa16cd1794
commit 4b8297a460
1 changed files with 21 additions and 27 deletions

View File

@ -11,7 +11,7 @@ mashiro_global.ini = new function () {
this.normalize = function () { this.normalize = function () {
lazyload(); lazyload();
social_share(); social_share();
mashiro_global.post_list_show_animation.ini(); post_list_show_animation();
copy_code_block(); copy_code_block();
coverVideoIni(); coverVideoIni();
checkskinSecter(); checkskinSecter();
@ -19,7 +19,7 @@ mashiro_global.ini = new function () {
this.pjax = function () { this.pjax = function () {
pjaxInit(); pjaxInit();
social_share(); social_share();
mashiro_global.post_list_show_animation.ini(); post_list_show_animation();
copy_code_block(); copy_code_block();
coverVideoIni(); coverVideoIni();
checkskinSecter(); checkskinSecter();
@ -64,31 +64,25 @@ function imgError(ele, type) {
} }
} }
mashiro_global.post_list_show_animation = new function () { function post_list_show_animation() {
this.ini = function (ajax) { if ($("article").hasClass("post-list-thumb")) {
$("article.post-list-thumb").each(function (i) { const options = {
if (ajax) { root: null,
var window_height = $(window).height(); threshold: [0.66]
} else {
if ($(".headertop").hasClass("headertop-bar")) {
var window_height = 0;
} else {
if (mashiro_option.land_at_home) {
var window_height = $(window).height() - 300;
} else {
var window_height = $(window).height();
} }
var io = new IntersectionObserver(callback, options);
let articles = document.querySelectorAll('.post-list-thumb');
function callback(entries) {
entries.forEach((article) => {
if (article.isIntersecting) {
article.target.classList.add("post-list-show");
io.unobserve(article.target)
} }
})
} }
var article_height = $("article.post-list-thumb").eq(i).offset().top; articles.forEach((article) => {
if ($(window).height() + $(window).scrollTop() >= article_height) io.observe(article)
$("article.post-list-thumb").eq(i).addClass('post-list-show'); })
$(window).scroll(function () {
var scrolltop = $(window).scrollTop();
if (scrolltop + window_height >= article_height && scrolltop)
$("article.post-list-thumb").eq(i).addClass("post-list-show");
});
});
} }
} }
mashiro_global.font_control = new function () { mashiro_global.font_control = new function () {
@ -1554,7 +1548,7 @@ var home = location.href,
$("#pagination a").removeClass("loading").text("Previous"); $("#pagination a").removeClass("loading").text("Previous");
$('#add_post span').removeClass("loading").text(""); $('#add_post span').removeClass("loading").text("");
lazyload(); lazyload();
mashiro_global.post_list_show_animation.ini(50); post_list_show_animation();
if (nextHref != undefined) { if (nextHref != undefined) {
$("#pagination a").attr("href", nextHref); $("#pagination a").attr("href", nextHref);
//加载完成上滑 //加载完成上滑