$.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-16570102338620").sub_banner('fadeInDown'); // 其他效果: fadeInUp fadeInDown fadeInLeft fadeInRight // $("#c_banner_019-1660963287521").sub_banner("fadeInRight"); });