Gustavo Luigi 2024-01-11 18:01:49 -03:00
parent 4b92e6e954
commit 7c2771ad33
1 changed files with 56 additions and 53 deletions

View File

@ -229,70 +229,73 @@
<script src="https://cdn.jsdelivr.net/npm/typed.js@2.0.12"></script>

<script>
// Get the elements
const targetElement = document.querySelector('#lumino-form-sent');
const elementToRemove = document.querySelector('.form-anchor');

// Create an Intersection Observer
const observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
// If target element is visible
if (entry.isIntersecting) {
// Remove the element to remove
elementToRemove.classList.remove('show');
} else {
const fixedElementRect = elementToRemove.getBoundingClientRect();
const referenceElementRect = targetElement.getBoundingClientRect();

if (fixedElementRect.bottom < referenceElementRect.top) {
// Show the element to remove
elementToRemove.classList.add('show');
} else {
// Hide the element to remove
elementToRemove.classList.remove('show');
}
}
// Stop observing once it's removed (optional)
// observer.unobserve(targetElement);
});
});

// Observe the target element
observer.observe(targetElement);

document.getElementById('link-to-form').addEventListener('click', function () {
const nameField = document.getElementById('name');
nameField.placeholder = "";
let formSent = "{!! session()->has('success') !!}";
if(!formSent){
// Get the elements
const targetElement = document.querySelector('#lumino-form-sent');
const elementToRemove = document.querySelector('.form-anchor');

// Create an Intersection Observer
const observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
// If target element is visible
if (entry.isIntersecting) {
let typedOptions = {
strings: ['Max Mustermann'],
typeSpeed: 50,
backSpeed: 25,
showCursor: false,
startDelay: 500,
loop: false,
attr: 'placeholder'
};
// Remove the element to remove
elementToRemove.classList.remove('show');
} else {
const fixedElementRect = elementToRemove.getBoundingClientRect();
const referenceElementRect = targetElement.getBoundingClientRect();

if(/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) {
nameField.focus();
setTimeout(() => new Typed('#name', typedOptions), 500);
if (fixedElementRect.bottom < referenceElementRect.top) {
// Show the element to remove
elementToRemove.classList.add('show');
} else {
// Hide the element to remove
elementToRemove.classList.remove('show');
}
else setTimeout(() => {
nameField.focus();
setTimeout(() => new Typed('#name', typedOptions), 500);
}, 2000);

observer.unobserve(targetElement);
}
// Stop observing once it's removed (optional)
// observer.unobserve(targetElement);
});
});

// Observe the target element
observer.observe(targetElement);
});

document.getElementById('link-to-form').addEventListener('click', function () {
const nameField = document.getElementById('name');
nameField.placeholder = "";
const targetElement = document.querySelector('#lumino-form-sent');

const observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
let typedOptions = {
strings: ['Max Mustermann'],
typeSpeed: 50,
backSpeed: 25,
showCursor: false,
startDelay: 500,
loop: false,
attr: 'placeholder'
};

if(/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) {
nameField.focus();
setTimeout(() => new Typed('#name', typedOptions), 500);
}
else setTimeout(() => {
nameField.focus();
setTimeout(() => new Typed('#name', typedOptions), 500);
}, 2000);

observer.unobserve(targetElement);
}
});
});

observer.observe(targetElement);
});
}
</script>
@stop