$(function () {
let lastScrollTop = 0;
var gundong = true;
var kvVideo = $(".kv_video")[0];
kvVideo.play();
if (
$(".ias-safety-setion2 .max").offset().top - 350 <
$(window).scrollTop()
) {
$(".ias-safety-setion2 .inlist .right .chart .x_zhou").addClass("active");
}
function initLazyVideos() {
$('.lazy-video').each(function() {
var $container = $(this);
var $video = $container.find('video');
// 清除可能存在的旧数据
$container.removeData('loaded playing');
// 标记是否已加载
$container.data('loaded', false);
$container.data('playing', false);
$container.data('load-initiated', false); // 新增:标记是否已开始加载
// 确保src为空
$video.attr('src', '');
// 移除之前可能绑定的事件
$video.off('loadeddata canplay');
});
}
// 检查视频是否需要加载或播放
function checkVideos() {
var scrollTop = $(window).scrollTop();
var windowHeight = $(window).height();
var windowBottom = scrollTop + windowHeight;
$('.lazy-video').each(function() {
var $container = $(this);
var $video = $container.find('video');
var videoElement = $video[0];
// 计算位置
var videoTop = $container.offset().top;
var videoHeight = $container.height();
var videoBottom = videoTop + videoHeight;
// 触发区域:视频顶部进入视窗底部,或视频底部在视窗顶部以上
var inViewport = videoBottom > scrollTop && videoTop < windowBottom;
// 播放区域:视频至少1/4在视窗内
var shouldPlay = (videoTop + videoHeight / 4) < windowBottom &&
(videoBottom - videoHeight / 4) > scrollTop;
// 只在需要时加载视频,且确保只加载一次
if (inViewport && !$container.data('load-initiated')) {
$container.data('load-initiated', true);
// 延迟一点加载,减少滚动时的瞬时请求
setTimeout(function() {
// 再次检查是否还在视口内(用户可能已经快速滚走了)
if ($container.data('load-initiated') && !$container.data('loaded')) {
var videoUrl = $container.attr('data-video');
// 设置src并加载
$video.attr('src', videoUrl);
$video.attr('preload', 'metadata'); // 只预加载元数据
$video.on('loadeddata canplay', function() {
$container.data('loaded', true);
// 只有在应该播放且不在播放中时才播放
if (shouldPlay && !$container.data('playing')) {
videoElement.play().then(function() {
$container.data('playing', true);
}).catch(function(error) {
console.log('播放失败:', error);
// 如果自动播放被阻止,可以显示播放按钮
if (error.name === 'NotAllowedError') {
// 可以在这里添加播放按钮
}
});
}
});
// 处理加载错误
$video.on('error', function() {
console.log('视频加载失败:', videoUrl);
$container.data('loaded', true); // 标记为已加载,避免重复尝试
});
}
}, 100); // 100ms延迟,减少快速滚动时的加载
}
// 控制播放/暂停(只对已加载的视频)
if ($container.data('loaded')) {
if (shouldPlay && videoElement.paused && !$container.data('playing')) {
videoElement.play().then(function() {
$container.data('playing', true);
}).catch(console.log);
} else if (!shouldPlay && !videoElement.paused && $container.data('playing')) {
videoElement.pause();
$container.data('playing', false);
}
}
});
}
// 使用防抖优化滚动性能
var scrollTimer;
var isScrolling = false;
$(window).on("scroll", function() {
clearTimeout(scrollTimer);
if (!isScrolling) {
// 滚动开始时立即检查一次
checkVideos();
isScrolling = true;
}
scrollTimer = setTimeout(function() {
// 滚动结束时再检查一次
checkVideos();
isScrolling = false;
}, 150); // 稍微增加防抖时间
});
// 监听页面可见性变化
$(document).on('visibilitychange', function() {
if (document.hidden) {
// 页面不可见时暂停所有视频
$('.lazy-video').each(function() {
var $container = $(this);
var $video = $container.find('video');
var videoElement = $video[0];
if ($container.data('playing') && !videoElement.paused) {
videoElement.pause();
$container.data('playing', false);
}
});
} else {
// 页面重新可见时检查是否需要播放
setTimeout(checkVideos, 100);
}
});
// 初始检查
$(document).ready(function() {
initLazyVideos();
setTimeout(checkVideos, 300); // 延迟初始检查
});
// 窗口大小改变时重新检查
$(window).on('resize', function() {
setTimeout(checkVideos, 200);
});
$(window).on("scroll", function () {
if (
$(".ias-safety-setion2").offset().top < $(window).scrollTop() &&
$(".ias-safety-setion2 .max").offset().top > $(window).scrollTop()
) {
$(".ias-safety-setion2").addClass("active");
} else {
$(".ias-safety-setion2").removeClass("active");
}
if ($(".ias-safety-setion3").offset().top - 100 < $(window).scrollTop()) {
$(".ias-qfx").addClass("active");
} else {
$(".ias-qfx").removeClass("active");
}
if (
$(".explore-con").offset().top - Number($(window).height()) / 1.2 >
$(window).scrollTop()
) {
$(".ias-qfx").removeClass("nhov");
} else {
$(".ias-qfx").addClass("nhov");
}
var zhuxinggao = 350;
if ($(window).width() < 899) {
const scrollTop = $(window).scrollTop();
if($(".ias-safety-setion3").hasClass('active')){
if (scrollTop > lastScrollTop) {
// 向下滚动
if (
$(".ias-safety-setion3.active").offset().top -
Number($(window).height()) / 1.8 <
scrollTop &&
scrollTop < $(".ias-safety-setion3.active").offset().top - 200 &&
gundong
) {
// $("body").addClass("no-scroll");
// $("html, body").animate(
// {
// scrollTop: $(".ias-safety-setion3").offset().top - 50,
// },
// {
// duration: 500,
// complete: function () {
// // 动画完成后恢复滚动
// $("body").removeClass("no-scroll");
// },
// }
// );
const leida = document.getElementById("leida");
leida.scrollIntoView({ block: "center", behavior: "smooth" });
gundong = false;
}
} else if (scrollTop < lastScrollTop) {
// 向上滚动
if (
$(".ias-safety-setion3").offset().top -
Number($(window).height()) * 1.55 <
scrollTop
) {
gundong = true;
}
}
}
lastScrollTop = scrollTop;
zhuxinggao = 150;
}
if (
$(".ias-safety-setion2 .max").offset().top - zhuxinggao <
$(window).scrollTop()
) {
$(".ias-safety-setion2 .inlist .right .chart .x_zhou").addClass("active");
} else {
$(".ias-safety-setion2 .inlist .right .chart .x_zhou").removeClass(
"active"
);
}
});
function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]);
return null;
}
if (getUrlParam("cid") == "appStore") {
$("body").addClass("app");
}
if ($(window).width() < 900) {
$(".safe-video-con").addClass("wow fadeInUp");
}
// 视频弹窗
$(".ias-car-body .ias-tpl-play-icon").click(function (e) {
e.preventDefault();
let kvurl = $(this).attr('data-kvurl');
let kvhash = $(this).attr('data-kvhash');
let kvactiontype = $(this).attr('data-kvactiontype');
let kvmodule = $(this).attr('data-kvmodule');
let kvbuttonname = $(this).attr('data-kvbuttonname');
let kvtitle = $(this).attr('data-kvtitle');
let videohash = $(this).attr('data-videohash');
let videoactiontype = $(this).attr('data-videoactiontype');
let videomodule = $(this).attr('data-videomodule');
let videourl = $(this).attr('data-videourl');
let videotitle = $(this).attr('data-videotitle');
$(".pop-con").addClass('active');
$(".pop-con video").attr('src', kvurl);
$(".pop-con video").attr('data-kvurl', kvurl);
$(".pop-con video").attr('data-kvhash', kvhash);
$(".pop-con video").attr('data-kvactiontype', kvactiontype);
$(".pop-con video").attr('data-kvmodule', kvmodule);
$(".pop-con video").attr('data-kvbuttonname', kvbuttonname);
$(".pop-con video").attr('data-kvtitle', kvtitle);
$(".pop-con video").attr('data-videohash', videohash);
$(".pop-con video").attr('data-videoactiontype', videoactiontype);
$(".pop-con video").attr('data-videomodule', videomodule);
$(".pop-con video").attr('data-videourl', videourl);
$(".pop-con video").attr('data-videotitle', videotitle);
$(".pop-con video")[0].play();
$(this).parent('.kv').find('video').addClass('active')
var vdbg=$(this).parent('.kv').find('video.active')[0]
vdbg.pause()
});
$(".pop-con .slide-close").click(function () {
$(".pop-con").removeClass('active');
$(".pop-con video")[0].pause();
var vdbg01=$('.kv').find('video.active')[0]
vdbg01.play()
setTimeout(function(){
$('.kv video.active').removeClass('active')
},100)
});
// 微信端
function isMobileWeChatBrowser() {
const ua = navigator.userAgent.toLowerCase();
const isWeChat = ua.indexOf("micromessenger") !== -1; // 微信浏览器检测:ml-citation{ref="2,7" data="citationList"}
const isMobile = /android|iphone|ipad/i.test(ua); // 移动端检测:ml-citation{ref="7,8" data="citationList"}
return isWeChat && isMobile;
}
// 使用示例
if (isMobileWeChatBrowser()) {
$(".video-wx").remove();
}
// WebP支持检测(首次运行时缓存结果)
function checkWebPSupport(callback) {
if (
typeof localStorage !== "undefined" &&
localStorage.getItem("webpSupport") !== null
) {
return callback(localStorage.getItem("webpSupport") === "true");
}
const img = new Image();
img.onload = function () {
const result = img.width > 0 && img.height > 0;
localStorage.setItem("webpSupport", result);
callback(result);
};
img.onerror = function () {
localStorage.setItem("webpSupport", false);
callback(false);
};
img.src =
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=";
}
checkWebPSupport(function (isSupported) {
$("img").each(function () {
const $img = $(this);
const webpSrc = $img
.closest("picture")
.find('source[type="image/webp"]')
.data("srcset");
const fallbackSrc = $img.data("src");
// 动态设置真实图片路径
$img.data("original", isSupported ? webpSrc : fallbackSrc);
});
$("img").lazyload({
threshold: 200,
effect: "fadeIn",
appear: function () {
const realSrc = $(this).data("original");
$(this).attr("src", realSrc);
$(this).addClass("lazy-loaded");
},
load: function () {
$(this).addClass("lazy-loaded");
},
error: function () {
$(this).attr("src", "img/error.jpg");
},
});
});
// 初始化懒加载
$("img").lazyload({
effect: "fadeIn", // 淡入效果
threshold: 100, // 提前300px加载
failure_limit: 15, // 最大容错数量
skip_invisible: true, // 加载隐藏图片
appear: function () {
// 加载前回调
$(this).css("background", "transparent");
$(this).removeClass("lazyload");
},
load: function () {
// 加载完成回调
$(this).addClass("lazy-loaded");
},
});
// 260107
var screenwidth = $(window).width();
var isUserInteractingcar = false;
var handscar = "null";
$(".more-secure-banner .swiper-slide").eq(0).find('video')[0].loop = true;
// 为什么华为乾崑智驾 ADS 更安全
var mySwiperKv = new Swiper(".more-secure-banner", {
// direction: "vertical",
loop: false,
pagination: {
el: ".swiper-pagination-more-secure",
clickable: true,
},
navigation: {
nextEl: ".swiper-button-next01",
prevEl: ".swiper-button-prev01",
},
slidesPerView: 1,
speed: 500,
// 20250925
autoplay: {
delay: 35000,
disableOnInteraction: false,
},
// autoplay: true,
spaceBetween: 0,
keyboard: true,
observer: true,
observeParents: true,
on: {
transitionStart: function (mySwiperKv) {
$(".ias-car-kvbanner").find("img").trigger("appear");
},
// 251125埋码
// 开始拖拽
// 监听触摸开始
touchStart: function () {
isUserInteractingcar = true;
},
// 监听滑动结束
touchEnd: function () {
// 短暂延迟后重置状态,确保能捕获到切换事件
clearTimeout(handscar);
handscar = setTimeout(() => {
isUserInteractingcar = false;
}, 1000);
},
slideChangeTransitionEnd: function () {
if (isUserInteractingcar) {
gatabswiper(this);
// 手动滑动后的处理逻辑
} else {
// 自动播放后的处理逻辑
}
// $('.swiper.more-secure-banner .swiper-slide .replay-con').hide();
var alledge_vd = $(".more-secure-banner .swiper-slide").find(
"video"
)[0];
alledge_vd.pause();
alledge_vd.currentTime = 0;
setTimeout(function () {
const $currentSlide = $(
`.more-secure-banner .swiper-slide.swiper-slide-active`
);
const $video = $currentSlide.find("video");
const videoElement = $video[0];
videoElement.loop = true;
videoElement.play();
// $('.more-secure-banner .swiper-slide.swiper-slide-active video').on('ended', function () {
// $('.swiper.more-secure-banner .swiper-slide.swiper-slide-active .replay-con').show();
// });
}, 200);
},
},
});
$(
".safe-video-con .tool-con .swiper-button-prev,.safe-video-con .tool-con .swiper-button-next"
).on("click", function () {
isUserInteractingcar = true;
setTimeout(() => {
isUserInteractingcar = false;
}, 1000);
});
// 260109
if (mySwiperKv && mySwiperKv.initialized) {
mySwiperKv.autoplay.stop();
$(
".safe-video-con .swiper-pagination-more-secure .swiper-pagination-bullet"
).removeClass("swiper-pagination-bullet-active");
}
var startflag = true;
$(window).scroll(function () {
var scrollTop = $(window).scrollTop();
var top = $(".more-secure-con").offset().top - 160;
var slide01 = $(
".safe-video-con .swiper-pagination-more-secure .swiper-pagination-bullet"
).eq(0);
if (scrollTop > top) {
if (startflag) {
slide01.addClass("swiper-pagination-bullet-active");
var vd = $(".more-secure-banner .swiper-slide").eq(0).find("video")[0];
vd.play();
mySwiperKv.autoplay.start();
}
startflag = false;
}
});
// $('.more-secure-banner .swiper-slide.swiper-slide-active video').on('ended', function () {
// $('.swiper.more-secure-banner .swiper-slide.swiper-slide-active .replay-con').show();
// });
$(".swiper.more-secure-banner .swiper-slide .replay-con").on(
"click",
function () {
$(this).parent().find("video")[0].currentTime = 0;
$(this).parent().find("video")[0].play();
// $(this).hide();
}
);
// 数据来源
$(".safe-data-con .safe-data-list li h3 ").on("click", function () {
$(this).parent().siblings().removeClass("active");
$(this).parent().siblings().find(".des-con").slideUp();
if ($(this).parent().hasClass("active")) {
$(this).parent().removeClass("active");
$(this).next(".des-con").slideUp();
} else {
$(this).parent().addClass("active");
$(this).next(".des-con").slideDown();
}
});
if ($(window).width() > 899) {
var isUserInteractingcar1 = false;
var handscar1 = "null";
$(".ias-safety-setion3 .ias-fang .right .swiper-slide").eq(0).find('video')[0].loop = true;
var mySwiperfang = new Swiper(".ias-safety-setion3 .ias-fang .right", {
loop: false,
effect: "fade",
pagination: {
el: ".ias-safety-setion3 .ias-fang .swiper-pagination",
clickable: true,
},
navigation: {
nextEl: ".ias-safety-setion3 .ias-fang .anniu .swiper-button-next",
prevEl: ".ias-safety-setion3 .ias-fang .anniu .swiper-button-prev",
},
slidesPerView: 1,
speed: 500,
// 20250925
autoplay: {
delay: 10000,
disableOnInteraction: false,
},
// autoplay: true,
spaceBetween: 0,
keyboard: true,
observer: true,
observeParents: true,
on: {
// 监听触摸开始
touchStart: function () {
isUserInteractingcar1 = true;
},
// 监听滑动结束
touchEnd: function () {
// 短暂延迟后重置状态,确保能捕获到切换事件
clearTimeout(handscar1);
handscar1 = setTimeout(() => {
isUserInteractingcar1 = false;
}, 1000);
},
slideChangeTransitionEnd: function () {
const dataIndex = this.activeIndex;
$(".ias-safety-setion3 .ias-fang .left .list")
.eq(dataIndex)
.addClass("active")
.siblings()
.removeClass("active");
if (isUserInteractingcar1) {
gatabswiper(this);
// 手动滑动后的处理逻辑
} else {
// 自动播放后的处理逻辑
}
var alledge_vd = $(".ias-safety-setion3 .ias-fang .right .list").find(
"video"
)[0];
alledge_vd.pause();
alledge_vd.currentTime = 0;
setTimeout(function () {
const $currentSlide = $(
`.ias-safety-setion3 .ias-fang .right .list.swiper-slide-active`
);
const $video = $currentSlide.find("video");
if ($video.length > 0) {
const videoElement = $video[0];
videoElement.loop = true;
videoElement.play();
}
}, 200);
},
},
});
$(
".ias-safety-setion3 .ias-fang .anniu .swiper-button-prev,.ias-safety-setion3 .ias-fang .anniu .swiper-button-next"
).on("click", function () {
isUserInteractingcar1 = true;
setTimeout(() => {
isUserInteractingcar1 = false;
}, 1000);
});
// 260109
if (mySwiperfang && mySwiperfang.initialized) {
mySwiperfang.autoplay.stop();
$(
".ias-safety-setion3 .ias-fang .swiper-pagination .swiper-pagination-bullet"
).removeClass("swiper-pagination-bullet-active");
}
var startflag1 = true;
$(window).scroll(function () {
var scrollTop1 = $(window).scrollTop();
var top1 = $(".ias-safety-setion3").offset().top - 160;
var slide011 = $(
".ias-safety-setion3 .ias-fang .swiper-pagination .swiper-pagination-bullet"
).eq(0);
if (scrollTop1 > top1) {
if (startflag1) {
slide011.addClass("swiper-pagination-bullet-active");
var vd1 = $(".ias-safety-setion3 .ias-fang .right .list")
.eq(0)
.find("video")[0];
vd1.play();
mySwiperfang.autoplay.start();
}
startflag1 = false;
}
});
} else {
var isUserInteractingcar1 = false;
var handscar1 = "null";
var mySwiperfang = new Swiper(".ias-safety-setion3 .ias-fang .right", {
loop: false,
effect: "fade",
slidesPerView: 1,
speed: 500,
// autoplay: true,
spaceBetween: 0,
keyboard: true,
observer: true,
observeParents: true,
noSwiping: true,
noSwipingClass: "stop-swiping",
on: {
// 监听触摸开始
touchStart: function () {
isUserInteractingcar1 = true;
},
// 监听滑动结束
touchEnd: function () {
// 短暂延迟后重置状态,确保能捕获到切换事件
clearTimeout(handscar1);
handscar1 = setTimeout(() => {
isUserInteractingcar1 = false;
}, 1000);
},
slideChangeTransitionEnd: function () {
if (isUserInteractingcar1) {
gatabswiper(this);
// 手动滑动后的处理逻辑
} else {
// 自动播放后的处理逻辑
}
var alledge_vd = $(".ias-safety-setion3 .ias-fang .right .list").find(
"video"
)[0];
alledge_vd.pause();
alledge_vd.currentTime = 0;
setTimeout(function () {
const $currentSlide = $(
`.ias-safety-setion3 .ias-fang .right .list.swiper-slide-active`
);
const $video = $currentSlide.find("video");
const videoElement = $video[0];
videoElement.loop = true;
videoElement.play();
}, 200);
},
},
});
$(
".ias-safety-setion3 .ias-fang .anniu .swiper-button-prev,.ias-safety-setion3 .ias-fang .anniu .swiper-button-next"
).on("click", function () {
isUserInteractingcar1 = true;
setTimeout(() => {
isUserInteractingcar1 = false;
}, 1000);
});
// 260109
if (mySwiperfang && mySwiperfang.initialized) {
mySwiperKv.autoplay.stop();
$(
".ias-safety-setion3 .ias-fang .swiper-pagination .swiper-pagination-bullet"
).removeClass("swiper-pagination-bullet-active");
}
var mySwiperQfx = new Swiper(".ias-qfx .mySwiper", {
direction: "vertical",
slidesPerView: 1.2,
loop: true,
centeredSlides: true,
navigation: {
nextEl: "#leida .mob_next",
prevEl: "#leida .mob_prev",
},
on: {
slideChangeTransitionEnd: function () {
const currentSlide = this.slides[this.activeIndex];
const dataIndex = currentSlide.getAttribute("data-index");
mySwiperfang.slideTo(dataIndex, 1000, false);
$(".ias-qfx-yuan .yuan").each(function () {
// 获取当前元素的类名
let classNames = $(this).attr("class") || "";
// 移除所有 active 开头的类(如 active0, active1, active2 等)
classNames = classNames.replace(/\bactive\d+\b/g, "");
// 添加新的 active+dataIndex 类
classNames += "active" + dataIndex;
// 更新类名
$(this).attr("class", classNames.trim());
});
if (dataIndex == 0 || dataIndex == 4) {
$(".ias-qfx").addClass("nhov");
}
$(".ias-safety-setion3 .ias-fang .left .list")
.eq(dataIndex)
.addClass("active")
.siblings()
.removeClass("active");
$(".ias-safety-setion3 .ias-fang .right .list")
.eq(dataIndex)
.addClass("active")
.siblings()
.removeClass("active");
gatabswiper(this);
var alledge_vd = $(".ias-safety-setion3 .ias-fang .right .list").find(
"video"
)[0];
alledge_vd.pause();
alledge_vd.currentTime = 0;
setTimeout(function () {
const $currentSlide = $(
`.ias-safety-setion3 .ias-fang .right .list.swiper-slide-active`
);
const $video = $currentSlide.find("video");
if ($video.length > 0) {
const videoElement = $video[0];
videoElement.loop = true;
videoElement.play();
}
}, 200);
},
},
});
}
});
(function ($) {
// 改进的数字滚动插件 - 滚动到上半屏时触发
$.fn.numberRoll = function (options) {
const settings = $.extend(
{
duration: 2000,
offset: 0.5, // 触发位置(屏幕高度的比例,0.5表示上半屏)
delay: 100, // 防抖延迟
once: true, // 是否只触发一次
mobileOffset: 0.7, // 移动端的触发位置
},
options
);
// 判断是否为移动设备
const isMobile =
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
navigator.userAgent
);
const triggerOffset = isMobile ? settings.mobileOffset : settings.offset;
return this.each(function () {
const $this = $(this);
const text = $this.text().trim();
// 提取数字(支持整数和小数)
const numMatch = text.match(/\d+(\.\d+)?/);
if (!numMatch) return;
const numStr = numMatch[0];
const num = parseFloat(numStr);
const originalText = $this.text(); // 保存原始文本
const isDecimal = numStr.includes(".");
const decimalPlaces = isDecimal ? numStr.split(".")[1].length : 0;
if (isNaN(num)) return;
let hasAnimated = false;
const elementId = "numberRoll-" + Math.random().toString(36).substr(2, 9);
$this.attr("data-roll-id", elementId);
// 检查元素是否在触发区域
function isInTriggerZone() {
const windowHeight = $(window).height();
const elementTop = $this.offset().top;
const elementBottom = elementTop + $this.outerHeight();
const scrollTop = $(window).scrollTop();
const triggerPoint = scrollTop + windowHeight * triggerOffset;
// 元素顶部进入触发点 或 元素底部进入触发点
return elementTop <= triggerPoint && elementBottom >= scrollTop;
}
// 格式化数字(处理小数和整数)
function formatNumber(value) {
if (isDecimal) {
// 处理小数:保留指定的小数位数
return value
.toFixed(decimalPlaces)
.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
} else {
// 处理整数:直接添加千分位
return Math.floor(value).toLocaleString("en-US");
}
}
// 执行数字滚动动画
function animateNumber() {
if (settings.once && hasAnimated) return;
hasAnimated = true;
$({ value: 0 }).animate(
{ value: num },
{
duration: settings.duration,
easing: "swing",
step: function (now) {
// 替换原始文本中的数字部分
const formattedNum = formatNumber(now);
const newText = originalText.replace(numStr, formattedNum);
$this.text(newText);
},
complete: function () {
// 最终值,确保精度
const finalNum = isDecimal
? num.toFixed(decimalPlaces)
: num.toString();
const finalFormatted = isDecimal
? finalNum.replace(/\B(?=(\d{3})+(?!\d))/g, ",")
: finalNum.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
const finalText = originalText.replace(numStr, finalFormatted);
$this.text(finalText);
},
}
);
}
// 防抖函数
let checkTimeout;
function checkVisibility() {
clearTimeout(checkTimeout);
checkTimeout = setTimeout(function () {
if (isInTriggerZone() && !hasAnimated) {
animateNumber();
}
}, settings.delay);
}
// 立即检查一次(如果已经在视图中)
checkVisibility();
// 监听滚动事件
$(window).on("scroll." + elementId, checkVisibility);
// 监听窗口大小变化(因为触发位置基于窗口高度)
$(window).on("resize." + elementId, checkVisibility);
// 提供手动触发的方法
$this.data("triggerNumberRoll", function () {
if (!hasAnimated) {
animateNumber();
}
});
// 提供重置的方法
$this.data("resetNumberRoll", function () {
hasAnimated = false;
$this.text(originalText);
checkVisibility();
});
// 提供销毁的方法
$this.data("destroyNumberRoll", function () {
$(window).off("scroll." + elementId);
$(window).off("resize." + elementId);
$this.removeData("triggerNumberRoll");
$this.removeData("resetNumberRoll");
$this.removeData("destroyNumberRoll");
$this.removeAttr("data-roll-id");
});
});
};
// 批量初始化所有带有特定类的元素
$.initNumberRoll = function (selector, options) {
$(selector || ".number-roll").numberRoll(options);
};
// DOM 加载完成后自动初始化
$(document).ready(function () {
// 可以选择性地自动初始化带有特定类的元素
// $.initNumberRoll('.number-roll');
});
})(jQuery);
$(".ias-safety-setion2 .inlist .left .list .txt span").numberRoll({
duration: 500, // 动画持续时间
offset: 1.2, // 触发位置(60%屏幕高度时触发)
mobileOffset: 0.8, // 移动端触发位置
once: true, // 只触发一次
delay: 50,
});
(function ($) {
// 改进的数字滚动插件 - 滚动到上半屏时触发
// 修改日期:2024-01-16 - 修复移动端横屏触摸不触发问题
$.fn.numberRoll1 = function (options) {
const settings = $.extend(
{
duration: 2000,
offset: 0.5, // 触发位置(屏幕高度的比例,0.5表示上半屏)
delay: 100, // 防抖延迟
once: true, // 是否只触发一次
mobileOffset: 0.2, // 移动端的触发位置
mobileLandscapeOffset: 1.2, // 新增:移动端横屏触发位置
mobileImmediate: true, // 移动端是否立即触发
desktopImmediate: false, // 桌面端是否立即触发
usePassiveEvents: true, // 使用被动事件监听器,提高性能
},
options
);
// 判断是否为移动设备
const isMobile = () => {
if (window.innerWidth <= 768) return true;
const userAgent = navigator.userAgent || navigator.vendor || window.opera;
return /android|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(userAgent.toLowerCase());
};
// 新增:判断是否为横屏模式
const isLandscape = () => {
// 优先使用orientation API
if (window.screen.orientation && window.screen.orientation.type) {
return window.screen.orientation.type.includes('landscape');
}
// 备选:使用窗口宽高比
return window.innerWidth > window.innerHeight;
};
// 新增:获取动态触发偏移量
const getDynamicOffset = () => {
if (!isMobile()) {
return settings.offset;
}
// 移动端:如果是横屏,使用更大的offset(更早触发)
if (isLandscape()) {
return settings.mobileLandscapeOffset || 1.2;
}
return settings.mobileOffset; // 竖屏使用默认值
};
return this.each(function () {
const $this = $(this);
const text = $this.text().trim();
// 提取数字(支持整数和小数)
const numMatch = text.match(/\d+(\.\d+)?/);
if (!numMatch) return;
const numStr = numMatch[0];
const num = parseFloat(numStr);
const originalText = $this.text(); // 保存原始文本
if (isNaN(num)) return;
let hasAnimated = false;
let isTouching = false; // 记录触摸状态
const elementId = "numberRoll-" + Math.random().toString(36).substr(2, 9);
$this.attr("data-roll-id", elementId);
// 检查元素是否在触发区域
function isInTriggerZone() {
if (!$this.is(":visible")) return false;
const windowHeight = $(window).height();
const elementTop = $this.offset().top;
const elementBottom = elementTop + $this.outerHeight();
const scrollTop = $(window).scrollTop();
// 修改:使用动态触发偏移量
const triggerOffset = getDynamicOffset();
const triggerPoint = scrollTop + windowHeight * triggerOffset;
// 元素顶部进入触发点 或 元素底部进入触发点
return elementTop <= triggerPoint && elementBottom >= scrollTop;
}
// 新增:检查元素是否在屏幕底部可见区域
function isInBottomVisibleZone() {
if (!$this.is(":visible")) return false;
const windowHeight = $(window).height();
const elementTop = $this.offset().top;
const elementBottom = elementTop + $this.outerHeight();
const scrollTop = $(window).scrollTop();
const scrollBottom = scrollTop + windowHeight;
// 判断元素是否进入屏幕底部区域(比如从底部出现1/4就触发)
const bottomZoneHeight = windowHeight * 0.25; // 底部25%区域
const bottomZoneTop = scrollBottom - bottomZoneHeight;
return elementTop <= bottomZoneTop && elementBottom >= scrollTop;
}
// 新增:检查元素是否在屏幕顶部可见区域
function isInTopVisibleZone() {
if (!$this.is(":visible")) return false;
const windowHeight = $(window).height();
const elementTop = $this.offset().top;
const elementBottom = elementTop + $this.outerHeight();
const scrollTop = $(window).scrollTop();
const scrollBottom = scrollTop + windowHeight;
// 判断元素是否进入屏幕顶部区域
const topZoneHeight = windowHeight * 0.25; // 顶部25%区域
const topZoneBottom = scrollTop + topZoneHeight;
return elementTop <= topZoneBottom && elementBottom >= scrollTop;
}
// 修改:优化移动端横屏触发逻辑
function checkMobileLandscapeTrigger() {
if (!isMobile() || !isLandscape()) {
return false;
}
// 横屏模式下:只要元素从底部出现一点点就触发
if (isInBottomVisibleZone()) {
// 额外检查:元素是否正在向上滚动进入视窗
if ($this.data('lastTop')) {
const lastTop = $this.data('lastTop');
const currentTop = $this.offset().top;
// 如果元素正在向上移动(进入视窗),立即触发
if (currentTop < lastTop) {
return true;
}
}
$this.data('lastTop', $this.offset().top);
// 如果元素从底部刚进入视窗,也触发
if (isInViewport() && !isInTopVisibleZone()) {
return true;
}
}
return false;
}
// 判断元素是否在视窗内
function isInViewport() {
if (!$this.is(":visible")) return false;
const windowHeight = $(window).height();
const elementTop = $this.offset().top;
const elementBottom = elementTop + $this.outerHeight();
const scrollTop = $(window).scrollTop();
const scrollBottom = scrollTop + windowHeight;
return elementTop < scrollBottom && elementBottom > scrollTop;
}
// 格式化数字为中文单位格式 - 未修改
function formatNumberWithUnits(value) {
const numValue = Math.floor(value);
const numStr = numValue.toString();
const length = numStr.length;
if (length <= 4) {
return numStr;
} else if (length <= 8) {
const wanPart = numStr.slice(0, length - 4);
const remainder = numStr.slice(length - 4);
if (remainder === "0000") {
return wanPart + '万';
} else {
return wanPart + '万' + remainder;
}
} else {
const yiPart = numStr.slice(0, length - 8);
const wanPart = numStr.slice(length - 8, length - 4);
const remainder = numStr.slice(length - 4);
let result = yiPart + '亿';
if (wanPart !== "0000") {
result += wanPart + '万';
}
if (remainder !== "0000") {
result += remainder;
}
if (wanPart === "0000" && remainder !== "0000") {
result = yiPart + '亿' + remainder;
}
return result;
}
}
// 执行数字滚动动画
function animateNumber() {
if (settings.once && hasAnimated) return;
if (hasAnimated) return;
hasAnimated = true;
$this.stop(true, true);
$({ value: 0 }).animate(
{ value: num },
{
duration: settings.duration,
easing: "swing",
step: function (now) {
const formattedNum = formatNumberWithUnits(now);
const newText = originalText.replace(numStr, formattedNum);
$this.html(newText);
},
complete: function () {
const finalFormatted = formatNumberWithUnits(num);
const finalText = originalText.replace(numStr, finalFormatted);
$this.html(finalText);
}
}
);
}
let rafId = null;
let lastCheckTime = 0;
const CHECK_INTERVAL = 50;
function checkVisibility() {
const now = Date.now();
if (now - lastCheckTime < CHECK_INTERVAL) {
return;
}
lastCheckTime = now;
if (rafId) {
cancelAnimationFrame(rafId);
rafId = null;
}
rafId = requestAnimationFrame(function() {
// 修改:优先检查移动端横屏特殊触发条件
if (checkMobileLandscapeTrigger() && !hasAnimated) {
animateNumber();
return;
}
// 然后检查常规触发条件
if (isInTriggerZone() && !hasAnimated) {
animateNumber();
}
});
}
// 立即检查函数
function checkImmediate() {
// 修改:移动端横屏也尝试立即触发
if (isMobile() && settings.mobileImmediate) {
if (isMobile() && isLandscape()) {
// 横屏时:只要在视窗内就立即触发
if (isInViewport() && !hasAnimated) {
setTimeout(() => {
if (!hasAnimated) animateNumber();
}, 100);
return true;
}
} else {
// 竖屏时:使用原有逻辑
if (isInViewport() && !hasAnimated) {
setTimeout(() => {
if (!hasAnimated) animateNumber();
}, 200);
return true;
}
}
}
// 如果是桌面端且设置了立即触发
if (!isMobile() && settings.desktopImmediate) {
if (isInViewport() && !hasAnimated) {
setTimeout(() => {
if (!hasAnimated) animateNumber();
}, 200);
return true;
}
}
return false;
}
function bindEvents() {
const passiveOptions = settings.usePassiveEvents ? { passive: true } : false;
window.addEventListener('scroll', checkVisibility, passiveOptions);
window.addEventListener('resize', checkVisibility, passiveOptions);
// 新增:监听屏幕方向变化
window.addEventListener('orientationchange', function() {
setTimeout(checkVisibility, 300); // 方向变化后稍等布局稳定
});
if (isMobile()) {
window.addEventListener('touchmove', checkVisibility, passiveOptions);
window.addEventListener('touchstart', function() {
isTouching = true;
checkVisibility();
}, passiveOptions);
window.addEventListener('touchend', function() {
isTouching = false;
setTimeout(checkVisibility, 50);
}, passiveOptions);
}
}
function unbindEvents() {
window.removeEventListener('scroll', checkVisibility);
window.removeEventListener('resize', checkVisibility);
window.removeEventListener('orientationchange', checkVisibility);
window.removeEventListener('touchmove', checkVisibility);
window.removeEventListener('touchstart', checkVisibility);
window.removeEventListener('touchend', checkVisibility);
if (rafId) {
cancelAnimationFrame(rafId);
rafId = null;
}
}
// 初始检查逻辑
function initCheck() {
// 先尝试立即触发
const immediateTriggered = checkImmediate();
// 如果立即触发失败,则使用滚动检测
if (!immediateTriggered) {
checkVisibility();
}
}
function init() {
bindEvents();
// 延迟初始化,确保DOM完全加载
setTimeout(initCheck, 100);
if ('IntersectionObserver' in window) {
// 修改:使用更敏感的IntersectionObserver配置
const observer = new IntersectionObserver(
function(entries) {
entries.forEach(entry => {
if (entry.isIntersecting && !hasAnimated) {
// 对于移动端横屏,使用更小的阈值
if (isMobile() && isLandscape()) {
// 横屏时立即触发
setTimeout(() => {
if (!hasAnimated) animateNumber();
}, 50);
} else {
setTimeout(checkVisibility, 50);
}
}
});
},
{
// 横屏时使用更大的rootMargin(更早触发)
rootMargin: isMobile() && isLandscape() ? '0px 0px 200px 0px' : '0px 0px 0px 0px',
threshold: 0.01 // 更小的阈值,元素出现1%就触发
}
);
observer.observe(this);
$this.data('intersectionObserver', observer);
}
}
init();
// 提供手动触发的方法
$this.data("triggerNumberRoll", function () {
if (!hasAnimated) {
animateNumber();
}
});
// 提供重置的方法
$this.data("resetNumberRoll", function () {
hasAnimated = false;
$this.text(originalText);
$this.removeData('lastTop'); // 新增:清除记录的位置数据
setTimeout(initCheck, 100);
});
// 提供销毁的方法
$this.data("destroyNumberRoll", function () {
unbindEvents();
const observer = $this.data('intersectionObserver');
if (observer) {
observer.disconnect();
$this.removeData('intersectionObserver');
}
$this.removeData("triggerNumberRoll");
$this.removeData("resetNumberRoll");
$this.removeData("destroyNumberRoll");
$this.removeData('lastTop'); // 新增:清除记录的位置数据
$this.removeAttr("data-roll-id");
});
});
};
// 批量初始化所有带有特定类的元素 - 未修改
$.initNumberRoll1 = function (selector, options) {
$(selector || ".number-roll1").numberRoll1(options);
};
// DOM 加载完成后自动初始化 - 未修改
$(document).ready(function () {
// 可以选择性地自动初始化带有特定类的元素
// $.initNumberRoll1('.number-roll1');
});
})(jQuery);
// 使用示例 - 移动端默认立即触发
$(document).ready(function() {
$("#pz").numberRoll1({
duration: 1000,
offset: 1.2,
mobileOffset: 1.2, // 移动端更容易触发
once: true,
delay: 200,
mobileImmediate: true, // 移动端立即触发
desktopImmediate: false // 桌面端保持原有逻辑
});
$("#gl").numberRoll1({
duration: 1000,
offset: 1.2,
mobileOffset: 1.2, // 移动端更容易触发
once: true,
delay: 200,
mobileImmediate: true, // 移动端立即触发
desktopImmediate: false // 桌面端保持原有逻辑
});
});
$("#lc").numberRoll1({
duration: 1000,
offset: 1.2,
mobileOffset: 0.8,
once: true,
delay: 500,
});
$(document).ready(function () {
// 状态变量
let animationStarted = false; // 动画是否开始
let currentProgress = 0; // 当前绘制进度(0到1)
let pathLength = 0; // SVG路径总长度
let startScrollY = 0; // 动画开始时的滚动位置
let borderVisible = true; // 边框是否可见
let lastScrollTop = 0; // 上次滚动位置
let isScrollingDown = true; // 当前滚动方向
let hasCompleted = false; // 【新增】是否已经完成过一次绘制
// DOM元素
const $icon = $("#targetIcon");
const $borderPath = $("#borderPath");
const $animatedBorder = $(".animated-border");
const $startLine = $("#startLine");
const $endLine = $("#endLine");
const $body = $("body");
// 配置参数
const CONFIG = {
startFromBottomPercent: 30, // 从底部往上30%
endFromTopPercent: 10, // 从顶部往下10%
animationDistance: 400, // 400像素的滚动距离完成动画
};
// 隐藏边框(绘制完成后)
function hideBorder() {
if (!borderVisible) return;
borderVisible = false;
hasCompleted = true; // 【新增】标记已完成一次绘制
console.log("边框绘制完成,隐藏边框");
// 添加淡出动画后隐藏
$animatedBorder.css({
transition: "opacity 0.3s ease-out",
opacity: "0",
});
// 动画完成后完全隐藏
setTimeout(() => {
$animatedBorder.hide();
}, 300);
}
// 显示边框(回滚时)
function showBorder() {
// 如果已经显示,不重复操作
if (borderVisible) return;
borderVisible = true;
console.log("回滚时显示边框");
// 先显示,然后淡入
$animatedBorder.css({
display: "block",
transition: "opacity 0.3s ease-out",
opacity: "1",
});
}
// 重置边框到初始状态
function resetBorder() {
borderVisible = true;
hasCompleted = false; // 【新增】重置完成标记
$animatedBorder.css({
display: "block",
transition: "none",
opacity: "1",
});
}
// 2024-11-21 修复PC端SVG路径计算问题
// 初始化SVG路径
function initBorderPath() {
// 检测设备类型
const isMobile = window.innerWidth <= 899;
// 根据设备设置不同的尺寸
let widthVW, heightVW, borderRadiusVW, borderOffsetVW;
if (isMobile) {
// 移动端尺寸
widthVW = 43.7333;
heightVW = 10.6667;
borderRadiusVW = 5.3333;
borderOffsetVW = 0.6667;
} else {
// PC端尺寸
widthVW = 19; // 从22改为19
heightVW = 4.4625;
borderRadiusVW = 2.7313;
borderOffsetVW = 0.2604;
}
// 计算实际尺寸(vw)
const totalWidthVW = widthVW + borderOffsetVW * 2;
const totalHeightVW = heightVW + borderOffsetVW * 2;
const totalRadiusVW = borderRadiusVW + borderOffsetVW;
// 将vw转换为当前视口的像素值
const vwToPx = window.innerWidth / 100;
const width = totalWidthVW * vwToPx;
const height = totalHeightVW * vwToPx;
const radius = totalRadiusVW * vwToPx;
const offsetPx = borderOffsetVW * vwToPx;
// 2024-11-21 修复:调整圆角矩形路径计算
// 计算内部矩形的实际尺寸(去除偏移)
const innerWidth = width - offsetPx * 2;
const innerHeight = height - offsetPx * 2;
// 计算有效圆角半径(确保不超过内部矩形尺寸的一半)
const maxRadius = Math.min(innerWidth / 2, innerHeight / 2);
const effectiveRadius = Math.min(radius, maxRadius);
// 2024-11-21 关键修复:重新计算所有坐标点
// 起点:左上角圆角结束点(从顶部中间开始绘制)
const startX = offsetPx + effectiveRadius;
const startY = offsetPx;
// 顶部直线终点
const topEndX = offsetPx + innerWidth - effectiveRadius;
const topEndY = offsetPx;
// 右上角圆角终点
const topRightCornerX = offsetPx + innerWidth;
const topRightCornerY = offsetPx + effectiveRadius;
// 右侧直线终点
const rightEndX = offsetPx + innerWidth;
const rightEndY = offsetPx + innerHeight - effectiveRadius;
// 右下角圆角终点
const bottomRightCornerX = offsetPx + innerWidth - effectiveRadius;
const bottomRightCornerY = offsetPx + innerHeight;
// 底部直线终点
const bottomEndX = offsetPx + effectiveRadius;
const bottomEndY = offsetPx + innerHeight;
// 左下角圆角终点
const bottomLeftCornerX = offsetPx;
const bottomLeftCornerY = offsetPx + innerHeight - effectiveRadius;
// 左侧直线终点
const leftEndX = offsetPx;
const leftEndY = offsetPx + effectiveRadius;
// 2024-11-21 修复:重新构建SVG路径,确保路径正确闭合
const path = `
M ${startX},${startY}
L ${topEndX},${topEndY}
Q ${topRightCornerX},${topEndY} ${topRightCornerX},${topRightCornerY}
L ${rightEndX},${rightEndY}
Q ${rightEndX},${bottomRightCornerY} ${bottomRightCornerX},${bottomRightCornerY}
L ${bottomEndX},${bottomEndY}
Q ${bottomLeftCornerX},${bottomEndY} ${bottomLeftCornerX},${bottomLeftCornerY}
L ${leftEndX},${leftEndY}
Q ${leftEndX},${startY} ${startX},${startY}
Z`;
// 应用路径
$borderPath.attr("d", path);
// 2024-11-21 调试:检查路径是否闭合
console.log("2024-11-21 修复:SVG路径参数调试");
console.log("innerWidth:", innerWidth, "innerHeight:", innerHeight);
console.log("effectiveRadius:", effectiveRadius);
console.log("起点坐标:", startX, startY);
console.log("右上角坐标:", topRightCornerX, topRightCornerY);
console.log("路径字符串:", path);
try {
pathLength = $borderPath[0].getTotalLength();
$borderPath.css({
"stroke-dasharray": pathLength,
"stroke-dashoffset": pathLength,
});
console.log("路径总长度:", pathLength);
} catch (e) {
pathLength = (innerWidth + innerHeight) * 2;
}
}
// 更新边框绘制
function updateBorderDrawing(scrollTop) {
if (!animationStarted) return;
// 计算滚动方向
const scrollDelta = scrollTop - lastScrollTop;
isScrollingDown = scrollDelta > 0;
// 【新增】回滚时显示边框的逻辑
if (!isScrollingDown && hasCompleted && !borderVisible) {
// 如果已经完成过一次绘制,并且正在向上滚动,且边框隐藏
showBorder();
}
// 计算进度 (0 到 1)
let progress = (scrollTop - startScrollY) / CONFIG.animationDistance;
progress = Math.max(0, Math.min(1, progress));
// 只有进度变化时才更新
if (Math.abs(progress - currentProgress) > 0.001) {
const oldProgress = currentProgress;
currentProgress = progress;
// 更新SVG边框
const dashoffset = pathLength * (1 - currentProgress);
$borderPath.css("stroke-dashoffset", dashoffset);
// 【修改】检测是否完成一圈绘制(仅当向下滚动时)
if (currentProgress >= 1 && borderVisible && isScrollingDown) {
hideBorder();
}
// 【新增】反向滚动的特殊处理
if (!isScrollingDown && currentProgress < oldProgress) {
// 正在向上滚动,并且进度在减少
// 确保边框是显示的
if (!borderVisible && hasCompleted) {
showBorder();
}
// 如果反向滚动到起点附近,重置状态
if (currentProgress <= 0.05) {
animationStarted = false;
hasCompleted = false;
console.log("反向滚动到起点,可以重新开始绘制");
}
}
}
lastScrollTop = scrollTop;
}
// 检查是否应该开始动画
function checkAnimationStart() {
const scrollTop = $(window).scrollTop();
const iconTop = $icon.offset().top;
const windowHeight = $(window).height();
// 元素顶部距离视口顶部的距离
const distanceFromTop = iconTop - scrollTop;
// 计算开始位置:从下往上30%
const startPosition =
windowHeight * (1 - CONFIG.startFromBottomPercent / 100);
// 计算结束位置:从上往下10%
const endPosition = windowHeight * (CONFIG.endFromTopPercent / 100);
// 当元素到达开始位置时开始动画
if (
distanceFromTop <= startPosition &&
distanceFromTop > -$icon.outerHeight() &&
!animationStarted
) {
animationStarted = true;
startScrollY = scrollTop;
// 开始新动画时确保边框显示
if (!borderVisible) {
showBorder();
}
// 更新触发线位置
updateTriggerLines();
console.log("动画开始!");
}
// 如果元素到达结束位置,确保动画完成
if (
animationStarted &&
distanceFromTop <= endPosition &&
currentProgress < 1 &&
isScrollingDown
) {
currentProgress = 1;
$borderPath.css("stroke-dashoffset", 0);
// 立即隐藏边框
if (borderVisible) {
hideBorder();
}
}
}
// 更新触发线位置
function updateTriggerLines() {
const windowHeight = $(window).height();
// 开始线位置:从下往上30%
const startLinePosition =
windowHeight * (1 - CONFIG.startFromBottomPercent / 100);
$startLine.css("top", startLinePosition + "px");
// 结束线位置:从上往下10%
const endLinePosition = windowHeight * (CONFIG.endFromTopPercent / 100);
$endLine.css("top", endLinePosition + "px");
}
// 滚动事件处理
let ticking = false;
$(window).on("scroll", function () {
const scrollTop = $(window).scrollTop();
if (!ticking) {
requestAnimationFrame(function () {
checkAnimationStart();
updateBorderDrawing(scrollTop);
ticking = false;
});
ticking = true;
}
});
// 窗口大小改变时重新计算
$(window).on("resize", function () {
initBorderPath();
updateTriggerLines();
// 重置状态
animationStarted = false;
currentProgress = 0;
hasCompleted = false;
$borderPath.css("stroke-dashoffset", pathLength);
resetBorder();
});
// 初始化
function init() {
initBorderPath();
updateTriggerLines();
lastScrollTop = $(window).scrollTop();
}
// 延迟初始化
setTimeout(init, 100);
// 开启调试模式
$(document).on("keydown", function (e) {
if (e.key === "d" || e.key === "D") {
$body.toggleClass("debug-mode");
console.log("调试模式:", $body.hasClass("debug-mode") ? "开启" : "关闭");
}
});
// 双击图标重置动画
$icon.on("dblclick", function () {
animationStarted = false;
currentProgress = 0;
hasCompleted = false;
$borderPath.css("stroke-dashoffset", pathLength);
$(window).scrollTop(0);
lastScrollTop = 0;
isScrollingDown = true;
// 重置边框
resetBorder();
console.log("动画已完全重置");
});
// 滚动到顶部时重置
$(window).on("scroll", function () {
const scrollTop = $(window).scrollTop();
// 滚动到顶部时完全重置
if (scrollTop === 0) {
animationStarted = false;
currentProgress = 0;
hasCompleted = false;
$borderPath.css("stroke-dashoffset", pathLength);
resetBorder();
}
});
});
// const scrollButton1 = document.getElementById("wen1");
// const section1 = document.getElementById("da1");
// scrollButton1.addEventListener("click", () => {
// if ($(window).width() > 899) {
// section1.scrollIntoView({ block: "center", behavior: "smooth" });
// } else {
// $(".ias-safety-setion3").removeClass('active');
// $("html, body").animate(
// {
// scrollTop: $("#da1").offset().top - ($(window).height()/1.3),
// },
// {
// duration: 500,
// complete: function () {
// // 动画完成后恢复滚动
// $("body").removeClass("no-scroll");
// $(".ias-safety-setion3").addClass('active');
// },
// }
// );
// }
// section1.classList.add("nhov");
// section2.classList.remove("nhov");
// section3.classList.remove("nhov");
// });
// const scrollButton2 = document.getElementById("wen2");
// const section2 = document.getElementById("da2");
// scrollButton2.addEventListener("click", () => {
// if ($(window).width() > 899) {
// section2.scrollIntoView({ block: "center", behavior: "smooth" });
// } else {
// $(".ias-safety-setion3").removeClass('active');
// setTimeout(function(){
// $("html, body").animate(
// {
// scrollTop: $("#da2").offset().top - ($(window).height()/1.3),
// },
// {
// duration: 500,
// complete: function () {
// // 动画完成后恢复滚动
// $("body").removeClass("no-scroll");
// $(".ias-safety-setion3").addClass('active');
// },
// }
// );
// },500)
// }
// section2.classList.add("nhov");
// section1.classList.remove("nhov");
// section3.classList.remove("nhov");
// });
// const scrollButton3 = document.getElementById("wen3");
// const section3 = document.getElementById("da3");
// scrollButton3.addEventListener("click", () => {
// if ($(window).width() > 899) {
// section3.scrollIntoView({ block: "center", behavior: "smooth" });
// } else {
// $(".ias-safety-setion3").removeClass('active');
// setTimeout(function(){
// $("html, body").animate(
// {
// scrollTop: $("#da3").offset().top - ($(window).height()/1.3),
// },
// {
// duration: 500,
// complete: function () {
// // 动画完成后恢复滚动
// $("body").removeClass("no-scroll");
// $(".ias-safety-setion3").addClass('active');
// },
// }
// );
// },500)
// }
// section3.classList.add("nhov");
// section1.classList.remove("nhov");
// section2.classList.remove("nhov");
// });