$.fn.sub_banner = function(effect) { let body = $("body"); if (isfrontenv()) { this.each(function() { // 添加统一样式,方便css统一管理 $(this).addclass("banner_text_effect"); let slide = $(this).find(".swiper-slide"); if(slide.length == 1) { $(this).addclass("no-prev-next"); } slide.first().addclass("swiper-slide-active"); // 设置动画效果 // 如果没有传递效果参数,就默认为fadein $(this).addclass(effect || "fadein"); // 将文本分离,并用span标签包裹 $(this).find(".text-white").each(function() { // 获取文本 let text = $(this).text(); // 去掉左右空白 text = text.trim(); // 将文本分离成数组 ["关", "于", "我", "们"] let text_array = text.split(""); // 将每个文本用span包裹 let html = text_array.join(""); // 加上头尾 html = "" + html + ""; // 替换文本 $(this).html(html); }); // 动画效果 $(this).find("span").each(function() { if (math.random() > 0.3) { // 设置随机延时,就有了随机出现的效果 $(this).css("animation-delay", (0.3 + math.random()) + "s"); } }); }); if (!body.hasclass("front")) { settimeout(a => { body.addclass("front"); }, 100); } } else { body.addclass("make"); } }; $(a => { // 默认fadein $("选择器").sub_banner(); $("#c_banner_019_p_406-1681455939252").sub_banner('fadeindown'); // 其他效果: fadeinup fadeindown fadeinleft fadeinright // $("#c_banner_019-1660963287521").sub_banner("fadeinright"); });