jquery - 预加载器 wordpress 最短时间
问题描述
我需要创建一个保持最短给定时间(6 秒)的预加载器。我对jQuery一无所知,但这是一个Wordpress插件的代码,我想我需要在这里添加时间:
jQuery(函数($){
var width = 100,
perfData = window.performance.timing, // The PerformanceTiming interface represents timing-related performance information for the given page.
EstimatedTime = -(perfData.loadEventEnd - perfData.navigationStart),
time = parseInt((EstimatedTime/1000)%60)*100;
var preloader = document.querySelector(".preloader-plus");
$('body').prepend(preloader);
var progBar = document.querySelector(".prog-bar"),
start = 0,
end = 70,
duration = time,
counter = document.getElementById("preloader-counter");
animateValue(progBar, start, end, duration);
function animateValue(element, start, end, duration) {
var range = end - start,
current = start,
increment = end > start? 1 : -1,
stepTime = Math.abs(Math.floor(duration / range)),
obj = element;
var timer = setInterval(function() {
if(current < end) {
current += increment;
}
if (obj !== null) {
obj.style["transition-duration"] = "0.001s";
obj.style.width= current + "%";
}
if (counter !== null) {
counter.innerHTML = current + "%";
}
if ( current == end ) {
var endLoading = setInterval( function() {
current += increment;
if (obj !== null) {
obj.style.width= current + "%";
}
if (counter !== null) {
counter.innerHTML = current + "%";
}
if(current == 100) {
setTimeout( function() {
$('body, .preloader-plus').addClass('complete');
}, preloader_plus.animation_delay)
clearInterval(endLoading);
}
}, 1)
clearInterval(timer);
}
}, stepTime);
}
});
如果你能帮助我会很高兴,谢谢!(如果您需要更多信息,请告诉我)
解决方案
推荐阅读
- python - 我无法让我的代码执行用户输入选择的函数
- python - RTU Modbus Slave 的 Python 脚本
- pyspark - 尝试从 PyCharm 运行 PySpark 应用程序时出现 SocketTimeoutException
- paypal - 具有多个定期订阅的贝宝只接受第一个
- javascript - 提取 Json 数据并使用 Protractor 验证值
- powerbi - SSAS 表格模型和 Power BI - 报表中的周筛选
- sql - 如何在报表生成器中合并行组?
- java - 如果需要更改库功能我该怎么办
- python - 尝试同时执行多个请求,然后使用 Aiohttp 和 python 添加到集合中
- azure - 通过 Microsoft graph api 将事件发布到组日历时出现持续 403 错误