perf: stagger JS initializations and remove duplicates to eliminate layout thrashing

This commit is contained in:
mstfyldz
2026-05-04 23:51:34 +03:00
parent 92a2be6f35
commit 4ea472fcc9

View File

@@ -51,274 +51,138 @@
}); });
} }
/* Delay heavy initializations to improve TBT and Main Thread work */ /*
setTimeout(function() { Sayfa performansını artırmak ve 'Layout Thrashing' hatalarını önlemek için
/* Hero Slider Layout JS */ ır kütüphaneleri kademeli (staggered) olarak başlatıyoruz.
const hero_slider_layout = new Swiper('.hero-slider-layout .swiper', { */
slidesPerView : 1,
speed: 1000,
spaceBetween: 0,
loop: true,
autoplay: {
delay: 4000,
},
pagination: {
el: '.hero-pagination',
clickable: true,
},
});
/* testimonial Slider JS */ // 1. Grup: Swiper Slider'lar (100ms)
if ($('.hero-client-slider').length) { setTimeout(function() {
const testimonial_slider = new Swiper('.hero-client-slider .swiper', { if ($('.hero-swiper').length) {
slidesPerView : 2, new Swiper('.hero-swiper', {
speed: 1000, speed: 1000, loop: true, autoplay: { delay: 5000 },
spaceBetween: 30, navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev' },
loop: true, pagination: { el: '.swiper-pagination', clickable: true }
autoplay: { });
delay: 5000, }
}, if ($('.hero-slider-layout .swiper').length) {
breakpoints: { new Swiper('.hero-slider-layout .swiper', {
768:{ slidesPerView: 1, speed: 1000, loop: true, autoplay: { delay: 4000 },
slidesPerView: 4, pagination: { el: '.hero-pagination', clickable: true }
}, });
991:{ }
slidesPerView: 5, if ($('.hero-client-slider').length) {
} new Swiper('.hero-client-slider .swiper', {
} slidesPerView: 2, speed: 1000, spaceBetween: 30, loop: true,
}); autoplay: { delay: 5000 },
} breakpoints: { 768: { slidesPerView: 4 }, 991: { slidesPerView: 5 } }
});
}
if ($('.services-slider').length) {
new Swiper('.services-slider .swiper', {
slidesPerView: 1, speed: 1000, spaceBetween: 30, loop: true,
autoplay: { delay: 5000 },
pagination: { el: '.services-pagination', clickable: true },
breakpoints: { 768: { slidesPerView: 2 }, 991: { slidesPerView: 3 } }
});
}
if ($('.testimonial-slider').length) {
new Swiper('.testimonial-slider .swiper', {
slidesPerView: 1, speed: 1000, spaceBetween: 30, loop: true,
autoplay: { delay: 5000 },
pagination: { el: '.testimonial-pagination', clickable: true },
navigation: { nextEl: '.testimonial-button-next', prevEl: '.testimonial-button-prev' },
breakpoints: { 768: { slidesPerView: 2 }, 991: { slidesPerView: 3 } }
});
}
if ($('.service-single-slider').length) {
new Swiper('.service-single-slider .swiper', {
slidesPerView: 1, speed: 1000, spaceBetween: 30, loop: true,
autoplay: { delay: 5000 },
pagination: { el: '.service-pagination', clickable: true }
});
}
}, 100);
/* Services Slider JS */ // 2. Grup: WOW.js & Animasyonlar (300ms)
if ($('.services-slider').length) { setTimeout(function() {
const services_slider = new Swiper('.services-slider .swiper', { if (typeof WOW !== 'undefined') {
slidesPerView : 1, new WOW({ boxClass: 'wow', animateClass: 'animated', offset: 0, mobile: true, live: true }).init();
speed: 1000, }
spaceBetween: 30, }, 300);
loop: true,
autoplay: {
delay: 5000,
},
pagination: {
el: '.services-pagination',
clickable: true,
},
breakpoints: {
768:{
slidesPerView: 2,
},
991:{
slidesPerView: 3,
}
}
});
}
/* testimonial Slider JS */ // 3. Grup: GSAP, ScrollTrigger & Text Effects (500ms)
if ($('.testimonial-slider').length) { setTimeout(function() {
const testimonial_slider = new Swiper('.testimonial-slider .swiper', { if (typeof gsap !== 'undefined' && typeof ScrollTrigger !== 'undefined') {
slidesPerView : 1, gsap.registerPlugin(ScrollTrigger);
speed: 1000,
spaceBetween: 30,
loop: true,
autoplay: {
delay: 5000,
},
pagination: {
el: '.testimonial-pagination',
clickable: true,
},
navigation: {
nextEl: '.testimonial-button-next',
prevEl: '.testimonial-button-prev',
},
breakpoints: {
768:{
slidesPerView: 2,
},
991:{
slidesPerView: 3,
}
}
});
}
/* Service Single Slider JS */ // Image Reveal
if ($('.service-single-slider').length) { let revealContainers = document.querySelectorAll(".reveal");
const testimonial_slider = new Swiper('.service-single-slider .swiper', { revealContainers.forEach((container) => {
slidesPerView : 1, let image = container.querySelector("img");
speed: 1000, let tl = gsap.timeline({ scrollTrigger: { trigger: container, toggleActions: "play none none none" } });
spaceBetween: 30, tl.set(container, { autoAlpha: 1 });
loop: true, tl.from(container, 1, { xPercent: -100, ease: Power2.out });
autoplay: { tl.from(image, 1, { xPercent: 100, scale: 1, delay: -1, ease: Power2.out });
delay: 5000, });
},
pagination: {
el: '.service-pagination',
clickable: true,
},
breakpoints: {
768:{
slidesPerView: 1,
},
991:{
slidesPerView: 1,
}
}
});
}
/* Image Reveal Animation */ // Text Styles
if ($('.reveal').length) { if (typeof SplitText !== 'undefined') {
gsap.registerPlugin(ScrollTrigger); document.querySelectorAll('.text-anime-style-1').forEach((el) => {
let revealContainers = document.querySelectorAll(".reveal"); let split = new SplitText(el, { type: "chars, words" });
revealContainers.forEach((container) => { gsap.from(split.words, { duration: 1, delay: 0.5, x: 20, autoAlpha: 0, stagger: 0.05, scrollTrigger: { trigger: el, start: "top 85%" } });
let image = container.querySelector("img"); });
let tl = gsap.timeline({ document.querySelectorAll('.text-anime-style-2').forEach((el) => {
scrollTrigger: { let split = new SplitText(el, { type: "chars, words" });
trigger: container, gsap.from(split.chars, { duration: 1, delay: 0.1, x: 20, autoAlpha: 0, stagger: 0.03, ease: "power2.out", scrollTrigger: { trigger: el, start: "top 85%" } });
toggleActions: "play none none none" });
} document.querySelectorAll('.text-anime-style-3').forEach((el) => {
}); el.split = new SplitText(el, { type: "lines,words,chars", linesClass: "split-line" });
tl.set(container, { gsap.set(el, { perspective: 400 });
autoAlpha: 1 gsap.set(el.split.chars, { opacity: 0, x: "50" });
}); gsap.to(el.split.chars, { scrollTrigger: { trigger: el, start: "top 90%" }, x: "0", y: "0", rotateX: "0", opacity: 1, duration: 1, ease: Back.easeOut, stagger: 0.02 });
tl.from(container, 1, { });
xPercent: -100, }
ease: Power2.out }
}); }, 500);
tl.from(image, 1, {
xPercent: 100,
scale: 1,
delay: -1,
ease: Power2.out
});
});
}
/* Text Effect Animation */ // 4. Grup: Parallax, Video, Counter & Magnific Popup (750ms)
if ($('.text-anime-style-1').length) { setTimeout(function() {
let staggerAmount = 0.05, if ($('.parallaxie').length && $(window).width() > 991) {
translateXValue = 0, $('.parallaxie').parallaxie({ speed: 0.55, offset: 0 });
delayValue = 0.5, }
animatedTextElements = document.querySelectorAll('.text-anime-style-1'); if ($('#herovideo').length) {
$("#herovideo").YTPlayer();
animatedTextElements.forEach((element) => { }
let animationSplitText = new SplitText(element, { type: "chars, words" }); if ($('.counter').length) {
gsap.from(animationSplitText.words, { $('.counter').counterUp({ delay: 6, time: 2000 });
duration: 1, }
delay: delayValue, if ($('.popup-video').length) {
x: 20, $('.popup-video').magnificPopup({
autoAlpha: 0, type: 'iframe',
stagger: staggerAmount, mainClass: 'mfp-fade',
scrollTrigger: { trigger: element, start: "top 85%" }, removalDelay: 160,
}); preloader: false,
}); fixedContentPos: true
} });
}
if ($('.text-anime-style-2').length) { if ($('.gallery-items').length) {
let staggerAmount = 0.03, $('.gallery-items').magnificPopup({
translateXValue = 20, delegate: 'a',
delayValue = 0.1, type: 'image',
easeType = "power2.out", closeOnContentClick: false,
animatedTextElements = document.querySelectorAll('.text-anime-style-2'); closeBtnInside: false,
mainClass: 'mfp-with-zoom',
animatedTextElements.forEach((element) => { image: { verticalFit: true },
let animationSplitText = new SplitText(element, { type: "chars, words" }); gallery: { enabled: true },
gsap.from(animationSplitText.chars, { zoom: {
duration: 1, enabled: true,
delay: delayValue, duration: 300,
x: translateXValue, opener: function(element) { return element.find('img'); }
autoAlpha: 0, }
stagger: staggerAmount, });
ease: easeType, }
scrollTrigger: { trigger: element, start: "top 85%"}, }, 750);
});
});
}
if ($('.text-anime-style-3').length) {
let animatedTextElements = document.querySelectorAll('.text-anime-style-3');
animatedTextElements.forEach((element) => {
//Reset if needed
if (element.animation) {
element.animation.progress(1).kill();
element.split.revert();
}
element.split = new SplitText(element, {
type: "lines,words,chars",
linesClass: "split-line",
});
gsap.set(element, { perspective: 400 });
gsap.set(element.split.chars, {
opacity: 0,
x: "50",
});
element.animation = gsap.to(element.split.chars, {
scrollTrigger: { trigger: element, start: "top 90%" },
x: "0",
y: "0",
rotateX: "0",
opacity: 1,
duration: 1,
ease: Back.easeOut,
stagger: 0.02,
});
});
}
/* Parallaxie js */
var $parallaxie = $('.parallaxie');
if($parallaxie.length && ($(window).width() > 991))
{
if ($(window).width() > 768) {
$parallaxie.parallaxie({
speed: 0.55,
offset: 0,
});
}
}
/* Animated Wow Js */
new WOW().init();
/* Youtube Background Video JS */
if ($('#herovideo').length) {
var myPlayer = $("#herovideo").YTPlayer();
}
}, 100);
/* Init Counter (Keep this faster or outside if needed) */
if ($('.counter').length) {
$('.counter').counterUp({ delay: 6, time: 3000 });
}
/* Zoom Gallery screenshot */
$('.gallery-items').magnificPopup({
delegate: 'a',
type: 'image',
closeOnContentClick: false,
closeBtnInside: false,
mainClass: 'mfp-with-zoom',
image: {
verticalFit: true,
},
gallery: {
enabled: true
},
zoom: {
enabled: true,
duration: 300, // don't foget to change the duration also in CSS
opener: function(element) {
return element.find('img');
}
}
});
/* Contact form validation */ /* Contact form validation */
var $contactform = $("#contactForm"); var $contactform = $("#contactForm");
@@ -332,7 +196,6 @@
} }
function submitForm(){ function submitForm(){
/* Ajax call to submit form */
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: "form-process.php", url: "form-process.php",
@@ -353,11 +216,7 @@
} }
function submitMSG(valid, msg){ function submitMSG(valid, msg){
if(valid){ var msgClasses = valid ? "h4 text-success" : "h4 text-danger";
var msgClasses = "h4 text-success";
} else {
var msgClasses = "h4 text-danger";
}
$("#msgSubmit").removeClass().addClass(msgClasses).text(msg); $("#msgSubmit").removeClass().addClass(msgClasses).text(msg);
} }
@@ -373,7 +232,6 @@
} }
function submitappointmentForm(){ function submitappointmentForm(){
/* Ajax call to submit form */
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: "form-appointment.php", url: "form-appointment.php",
@@ -394,23 +252,8 @@
} }
function appointmentsubmitMSG(valid, msg){ function appointmentsubmitMSG(valid, msg){
if(valid){ var msgClasses = valid ? "h3 text-success" : "h3 text-danger";
var msgClasses = "h3 text-success";
} else {
var msgClasses = "h3 text-danger";
}
$("#msgSubmit").removeClass().addClass(msgClasses).text(msg); $("#msgSubmit").removeClass().addClass(msgClasses).text(msg);
} }
/* Popup Video */
if ($('.popup-video').length) {
$('.popup-video').magnificPopup({
type: 'iframe',
mainClass: 'mfp-fade',
removalDelay: 160,
preloader: false,
fixedContentPos: true
});
}
})(jQuery); })(jQuery);