前端优化
This commit is contained in:
@@ -58,17 +58,18 @@ function isMobile() {
|
||||
|
||||
// 懒加载
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
|
||||
// 通用懒加载函数
|
||||
function lazyLoad(elements, callback) {
|
||||
const observer = new IntersectionObserver((entries, observer) => {
|
||||
entries.forEach(entry => {
|
||||
if (entry.isIntersecting) {
|
||||
const element = entry.target;
|
||||
callback(element); // 执行懒加载逻辑
|
||||
observer.unobserve(element); // 停止观察
|
||||
callback(element);
|
||||
observer.unobserve(element);
|
||||
}
|
||||
});
|
||||
}, {
|
||||
rootMargin: '100px' // 提前 100px 开始加载
|
||||
});
|
||||
|
||||
elements.forEach(element => observer.observe(element));
|
||||
@@ -79,8 +80,16 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
lazyLoad(lazyBackgrounds, (element) => {
|
||||
const src = element.getAttribute("data-src");
|
||||
if (src) {
|
||||
element.style.backgroundImage = `url(${src})`;
|
||||
element.classList.remove("lazyload-bg");
|
||||
const img = new Image();
|
||||
img.src = src;
|
||||
img.onload = () => {
|
||||
element.style.backgroundImage = `url(${src})`;
|
||||
element.classList.remove("lazyload-bg");
|
||||
};
|
||||
img.onerror = () => {
|
||||
// console.error(`Failed to load background image: ${src}`);
|
||||
// 可选:设置默认背景或错误提示
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
@@ -89,8 +98,16 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
lazyLoad(lazyImages, (element) => {
|
||||
const src = element.getAttribute("data-src");
|
||||
if (src) {
|
||||
element.setAttribute("src", src);
|
||||
element.classList.remove("lazyload-img");
|
||||
const img = new Image();
|
||||
img.src = src;
|
||||
img.onload = () => {
|
||||
element.setAttribute("src", src);
|
||||
element.classList.remove("lazyload-img");
|
||||
};
|
||||
img.onerror = () => {
|
||||
// console.error(`Failed to load image: ${src}`);
|
||||
// 可选:设置占位图或错误提示
|
||||
};
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -465,9 +482,16 @@ function initDPlayer(strPlayUrl) {
|
||||
// 监听当前播放时间
|
||||
videoPlayer.on('timeupdate', function () {
|
||||
if (strPlayType == 'default' || strPlayType == 'youzhi') {
|
||||
if (videoPlayer.video.currentTime >= 476 && videoPlayer.video.currentTime < 494) { //18秒
|
||||
videoPlayer.seek(495); // 跳过到 494 秒
|
||||
// 07:55 08:14
|
||||
// if (videoPlayer.video.currentTime >= 476 && videoPlayer.video.currentTime < 494) { //18秒
|
||||
// videoPlayer.seek(495); // 跳过到 494 秒
|
||||
// }
|
||||
|
||||
// 06:55 07:12
|
||||
if (videoPlayer.video.currentTime >= 415 && videoPlayer.video.currentTime < 432) { //20秒
|
||||
videoPlayer.seek(1833); // 跳过到 494 秒
|
||||
}
|
||||
|
||||
// 30:15 30:32
|
||||
if (videoPlayer.video.currentTime >= 1812 && videoPlayer.video.currentTime < 1832) { //20秒
|
||||
videoPlayer.seek(1833); // 跳过到 494 秒
|
||||
@@ -480,8 +504,41 @@ function initDPlayer(strPlayUrl) {
|
||||
if (videoPlayer.video.currentTime >= 6046 && videoPlayer.video.currentTime < 6067) { //19秒
|
||||
videoPlayer.seek(6068); // 跳过到 494 秒
|
||||
}
|
||||
}else if (strPlayType == 'fengchao') {
|
||||
// if (videoPlayer.video.currentTime >= 476 && videoPlayer.video.currentTime < 494) { //18秒
|
||||
// videoPlayer.seek(495); // 跳过到 494 秒
|
||||
// }
|
||||
// // 30:15 30:32
|
||||
// if (videoPlayer.video.currentTime >= 1812 && videoPlayer.video.currentTime < 1832) { //20秒
|
||||
// videoPlayer.seek(1833); // 跳过到 494 秒
|
||||
// }
|
||||
// // 01:00:32 - 01:00:50
|
||||
// if (videoPlayer.video.currentTime >= 3631 && videoPlayer.video.currentTime < 3650) { //19秒
|
||||
// videoPlayer.seek(3651); // 跳过到 494 秒
|
||||
// }
|
||||
// // 01:40:48 - 01:40:48
|
||||
// if (videoPlayer.video.currentTime >= 6046 && videoPlayer.video.currentTime < 6067) { //19秒
|
||||
// videoPlayer.seek(6068); // 跳过到 494 秒
|
||||
// }
|
||||
}else if (strPlayType == 'wuxian') {
|
||||
// if (videoPlayer.video.currentTime >= 476 && videoPlayer.video.currentTime < 494) { //18秒
|
||||
// videoPlayer.seek(495); // 跳过到 494 秒
|
||||
// }
|
||||
// // 30:15 30:32
|
||||
// if (videoPlayer.video.currentTime >= 1812 && videoPlayer.video.currentTime < 1832) { //20秒
|
||||
// videoPlayer.seek(1833); // 跳过到 494 秒
|
||||
// }
|
||||
// // 01:00:32 - 01:00:50
|
||||
// if (videoPlayer.video.currentTime >= 3631 && videoPlayer.video.currentTime < 3650) { //19秒
|
||||
// videoPlayer.seek(3651); // 跳过到 494 秒
|
||||
// }
|
||||
// // 01:40:48 - 01:40:48
|
||||
// if (videoPlayer.video.currentTime >= 6046 && videoPlayer.video.currentTime < 6067) { //19秒
|
||||
// videoPlayer.seek(6068); // 跳过到 494 秒
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
@@ -543,9 +600,11 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
if (typeof strPlayType !== "undefined"){
|
||||
if (strPlayType == 'default') {
|
||||
strPlayUrl = findFirstUrl(arrPlayUrl)
|
||||
// checkLine(strPlayType);
|
||||
} else {
|
||||
var ActivePlayUrl = arrPlayUrl[strPlayType][intPlayUrlIndex - 1]
|
||||
strPlayUrl = ActivePlayUrl.url
|
||||
checkLine(strPlayType);
|
||||
}
|
||||
initDPlayer(strPlayUrl)
|
||||
}
|
||||
|
||||
BIN
code/public/static/img/loading.webp
Normal file
BIN
code/public/static/img/loading.webp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.5 KiB |
BIN
code/public/static/img/loading3.gif
Normal file
BIN
code/public/static/img/loading3.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
BIN
code/public/static/img/loading4.gif
Normal file
BIN
code/public/static/img/loading4.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
Reference in New Issue
Block a user