Код: Выделить всё
let scrollAmount = window.innerWidth < 768 ? 50 : 100;
Код: Выделить всё
btnScrollUp.addEventListener('click', () => scrollVertically(1));
btnScrollUp.addEventListener('touchstart', () => scrollVertically(1));
btnScrollDown.addEventListener('click', () => scrollVertically(-1));
btnScrollDown.addEventListener('touchstart', () => scrollVertically(-1));
Код: Выделить всё
//scrolling of testimonial cards
document.addEventListener('DOMContentLoaded', function() {
const cardWrapper = document.querySelector('.card-wrapper');
const btnScrollUp = document.getElementById('btn-scroll-up');
const btnScrollDown = document.getElementById('btn-scroll-down');
let scrollAmount = window.innerWidth < 768 ? 50 : 100; // Adjust scroll amount based on screen size
function scrollVertically(direction) {
const scrollHeight = cardWrapper.scrollHeight;
const clientHeight = cardWrapper.clientHeight;
const currentScrollPosition = cardWrapper.scrollTop;
// Scroll up
if (direction === 1) {
cardWrapper.scrollBy({
top: -scrollAmount,
behavior: 'smooth'
});
}
// Scroll down
else {
cardWrapper.scrollBy({
top: scrollAmount,
behavior: 'smooth'
});
}
// Update button visibility after scrolling
setTimeout(updateScrollButtons, 300); // Delay to allow for smooth scrolling
}
function updateScrollButtons() {
const currentScrollPosition = cardWrapper.scrollTop;
const maxScrollHeight = cardWrapper.scrollHeight - cardWrapper.clientHeight;
if (currentScrollPosition = maxScrollHeight) {
btnScrollDown.style.display = 'none'; // Hide down button
} else {
btnScrollDown.style.display = 'flex'; // Show down button
}
}
// Initialize scroll button visibility
updateScrollButtons();
// Event listeners for buttons
btnScrollUp.addEventListener('click', () => scrollVertically(1));
btnScrollUp.addEventListener('touchstart', () => scrollVertically(1));
btnScrollDown.addEventListener('click', () => scrollVertically(-1));
btnScrollDown.addEventListener('touchstart', () => scrollVertically(-1));
// Add scroll event listener to update button visibility when scrolling manually
cardWrapper.addEventListener('scroll', updateScrollButtons);
// Add event listeners for "View More" buttons
const viewMoreButtons = document.querySelectorAll('.view-more-btn');
viewMoreButtons.forEach(button => {
button.addEventListener('click', function() {
const cardDetails = this.parentElement.querySelector('.card-text');
cardDetails.classList.toggle('expanded'); // Toggle the expanded class
// Scroll to the bottom of the card wrapper if expanding the last card
if (this.closest('.card') === cardWrapper.lastElementChild) {
cardWrapper.scrollTo({
top: cardWrapper.scrollHeight, // Scroll to the bottom of the card wrapper
behavior: 'smooth' // Smooth scroll
});
}
this.textContent = cardDetails.classList.contains('expanded') ? 'View Less' : 'View More'; // Change button text
// Update scroll button visibility
updateScrollButtons();
});
});
});< /code>
.testimonial-container-right {
grid-area: testimonial-container-right;
display: flex;
flex-direction: column;
}
.vertical-scroll {
display: flex;
align-items: center;
justify-content: center;
position: relative;
/* Change to relative for positioning */
}
.btn-scroll {
font-size: 2rem;
outline: none;
border: none;
color: var(--white);
cursor: pointer;
background: var(--primary-color);
transition: .3s all ease;
}
#btn-scroll-up,
#btn-scroll-down {
position: absolute;
left: 50%;
transform: translateX(-50%);
display: flex;
/* Ensure it's displayed as a flex container */
z-index: 1;
padding: .5rem 1rem;
}
#btn-scroll-up {
border-radius: 0 0 1rem 1rem;
top: 0;
}
#btn-scroll-down {
border-radius: 1rem 1rem 0 0;
bottom: 0;
}
.btn-scroll:hover,
.btn-scroll:focus {
background-color: var(--secondary-color);
}
.card-wrapper {
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
gap: 1rem;
height: 650px;
overflow-y: hidden;
position: relative;
}
.card {
padding: 2rem;
display: flex;
flex-direction: row;
align-items: flex-start;
gap: 1rem;
background-color: var(--white);
border-radius: 1rem;
cursor: pointer;
max-height: auto;
border: 1px solid var(--secondary-color);
-webkit-user-select: none;
/* Safari */
-ms-user-select: none;
/* IE 10 and IE 11 */
user-select: none;
/* Standard syntax */
max-width: 650px;
/*word-break: break-all;*/
}
.testi-image {
display: flex;
align-items: center;
justify-content: center;
}
.card img {
width: 75px;
/* Set a max width for the preview */
height: 75px;
/* Set a max height for the preview */
border-radius: 50%;
border: 1px solid #eee;
float: none;
pointer-events: none;
}
.card__content {
display: flex;
gap: 1rem;
flex: 1;
max-width: 100%;
}
.card__content span i {
font-size: 2rem;
color: var(--primary-color);
}
.card__details {
flex-grow: 1;
/* Allow it to grow */
flex-shrink: 1;
/* Allow it to shrink */
min-width: 0;
/* Avoid forcing unnecessary width */
max-width: 100%;
/* Prevent overflow beyond container */
overflow: hidden;
}
.card__details p {
max-width: 100%;
font-size: 1rem;
font-style: italic;
font-weight: 400;
color: var(--text-dark);
margin-right: 1rem;
margin-bottom: 1rem;
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 3;
/* Limit to 3 lines */
-webkit-box-orient: vertical;
transition: max-height 0.3s ease;
max-height: 4.5em;
/* Adjust based on line height */
}
.card__details p.expanded {
-webkit-line-clamp: unset;
/* Remove line limit */
max-height: none;
/* Allow full height */
}
.card__details h4 {
text-align: right;
color: var(--primary-color);
font-size: 1rem;
font-weight: 500;
}
.card__details h5 {
text-align: right;
color: var(--primary-color);
font-size: .8rem;
font-weight: 400;
margin-bottom: .1rem;
}
.card__details h6 {
text-align: right;
color: var(--text-light);
font-size: .7rem;
font-weight: 400;
display: flex;
/* Use flexbox for better alignment */
align-items: center;
/* Center align items vertically */
justify-content: flex-end;
/* Align content to the right */
margin-top: 0;
margin-bottom: 0;
}
.rating-stars_in_card {
height: 30px;
position: absolute;
vertical-align: baseline;
color: #b9b9b9;
line-height: 10px;
float: left;
margin: 1rem 0;
}
.card__details button {
padding: .5rem 1rem;
outline: none;
border: none;
border-radius: 5px;
background: linear-gradient(to right, #ff226f,
#fe6769);
color: var(--white);
font-size: .8rem;
cursor: pointer;
}< /code>
[i][/i]
Подробнее здесь: [url]https://stackoverflow.com/questions/79381669/scrolling-function-not-working-in-mobile-browsers[/url]
Мобильная версия