I need to apply some styles to an element when the user scrolls the window horizontally, using JavaScript. The element is wider than the window. When The styles are added later, they are applied only to the part that you can see before scrolling horizontally to see the rest that's overflowing out of the window.
https://codepen.io/sleepydada/pen/RLBqYW
HTML:
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
CSS:
* {
box-sizing: border-box;
}
ul {
list-style: none;
display: flex;
border-right: 13px solid yellow;
padding:0;
li {
background:red;
flex: 0 0 250px;
height: 250px;
border: 1px solid black;
box-shadow: 0 4px 2px -2px gray;
}
&.added {
border: 10px solid blue;
}
}
JS:
var ul = document.querySelector('ul')
window.addEventListener('scroll', function() {
ul.classList.add('added')
})
lilist it's working . try this one&.added li { border-top: 10px solid blue; border-bottom:10px solid blue; } .added li::first-child{ border-left: 10px solid blue; } .added li::last-child{ border-right: 10px solid blue; }