'Disable VERTICAL Scroll only
Bonjour amis développeur ! ,
Since yesterday i'm blocking to block a vertical scrolling of my site but just the vertical, i create a slider with parallax effect and i need to Scroll horizontaly Without Wordpress in a simple HTML / CSS / JS is good but when i integrated in Wordpress the scroll (With the mousse) doesn't :( !
The Scroll bar is here but 0 Scroll with mousse
I'm Share my code, if you have a idea to disable Scroll vertical and Active horizontale you save me ! :p
A French studend, Antoine see u !!
let slider = document.querySelector('.slider');
let sliderWidth;
let imageWidth;
let current = 0;
let target = 0;
let ease = .05;
let images = [...document.querySelectorAll('.img')];
images.forEach((img, idx) => {
img.style.backgroundImage = `url(https://www.industrialempathy.com/img/remote/ZiClJf-1920w.jpg)`
})
function lerp(start, end, t) {
return start * (1 - t) + end * t;
}
function setTransform(el, transform) {
el.style.transform = transform;
}
function init() {
sliderWidth = slider.getBoundingClientRect().width;
imageWidth = sliderWidth / images.length;
document.body.style.height = `${sliderWidth - (window.innerWidth - window.innerHeight)}px`
}
function animate() {
current = parseFloat(lerp(current, target, ease)).toFixed(2);
target = window.scrollY;
setTransform(slider, `translateY(-${current}px)`)
animatedImage();
requestAnimationFrame(animate);
}
function animatedImage() {
let ratio = current / imageWidth;
let RatioValue;
images.forEach((image) => {
RatioValue = ratio - (0.2);
setTransform(image, `translateX(-${RatioValue * 20}px)`)
})
}
init();
animate();
@media (min-width: 800px) {
body{
background-color: #F2F2F2;
box-sizing: border-box;
overflow-x:scroll;
overflow-y: hidden;
}
main {
top: 0;
left: 0;
width: 100%;
height: 100vh;
display: flex;
}
.slider {
position: absolute;
top: 0;
left: 0;
width: 3400px;
height: 68%;
}
.slider-inner {
position: fixed;
top: 15%;
width: 100%;
height: 50%;
display: flex;
justify-content: space-around;
}
.item {
position: relative;
width: 400px;
height: 100%;
overflow: hidden;
padding-top: 6%;
}
.img {
position: absolute;
width: 500px;
height: 100%;
background-size: cover;
background-position: center;
}
.title {
background-color: #F2F2F2;
text-align:center ;
padding: 12px;
}
.link {
text-decoration: none;
color: #053D21 ;
}
.link:hover {
text-decoration: none;
color: #EA734E ;
}
}
@media (max-width: 801px) {
.title {
background-color: #F2F2F2;
text-align:center ;
padding-top: 12px;
padding-bottom: 12px;
margin-bottom: 15%;
width:100%;
}
body{
background-color: #F2F2F2;
margin: 0 ;
}
main {
position: absolute;
width: 100%;
height: auto;
}
.slider-inner {
display: block;
justify-content: center;
}
.slider {
display: flex;
flex-wrap: wrap;
}
.item {
border: solid 2px brown;
width:90%;
height: 20%;
}
.img {
width:95%;
height: 100%;
background-size: contain;
background-repeat: no-repeat;
}
.slider-inner {
width: 100%;
height: auto;
}
.link {
text-decoration: none;
color: #053D21 ;
}
.link:hover {
text-decoration: none;
color: #EA734E ;
}
}
<main>
<div class="slider" align="center" >
<div class="slider-inner">
<a href="#" class="link">
<div class="item">
<div class="img" ></div>
</div>
<div class="title"><h2>Ma super vidéo</h2></div>
</a>
<section>
<a href="#" class="link">
<div class="item">
<div class="img" ></div>
</div>
<div class="title"><h2>Ma super vidéo</h2></div>
</a>
</section>
<section>
<a href="#" class="link">
<div class="item">
<div class="img" ></div>
</div>
<div class="title"><h2>Ma super vidéo</h2></div>
</a>
</section>
<section>
<a href="#" class="link">
<div class="item">
<div class="img" ></div>
</div>
<div class="title"><h2>Ma super vidéo</h2></div>
</a>
</section>
<section>
<a href="#" class="link">
<div class="item">
<div class="img" ></div>
</div>
<div class="title"><h2>Ma super vidéo</h2></div>
</a>
</section>
<section>
<a href="#" class="link">
<div class="item">
<div class="img" ></div>
</div>
<div class="title"><h2>Ma super vidéo</h2></div>
</a>
</section>
<section>
<a href="#" class="link">
<div class="item">
<div class="img" ></div>
</div>
<div class="title"><h2>Ma super vidéo</h2></div>
</a>
</section>
</div>
</div>
</div>
</main>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|