JSFiddle - React, Tailwind, and code Playground
by Dhanck
HTML
<div class="card-panel">
<div class="inline-cards">
<div class="card-item">
<img src="https://images.unsplash.com/photo-1553388469-94f50e9e0fbb?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60" />
</div>
<div class="card-item">
<img src="https://images.unsplash.com/photo-1553388469-94f50e9e0fbb?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60" />
</div>
<div class="card-item">
<img src="https://images.unsplash.com/photo-1553388469-94f50e9e0fbb?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60" />
</div>
<div class="card-item">
<img src="https://images.unsplash.com/photo-1553388469-94f50e9e0fbb?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60" />
</div>
<div class="card-item">
<img src="https://images.unsplash.com/photo-1553388469-94f50e9e0fbb?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60" />
</div>
</div>
</div>
CSS
.card-panel {
height: 310px;
overflow-x: auto;
overflow-y: hidden;
margin: 10px;
}
.fa-chevron-left {
position: absolute;
left: 18px;
background: #9c9c9c2e;
padding: 138px 30px;
}
.fa-chevron-right {
position: absolute;
right: 18px;
background: #9c9c9c2e;
padding: 138px 30px;
}
.fa-chevron-right:hover {
background: #9c9c9c94;
cursor: pointer;
}
.inline-cards {
display: inline-flex;
}
.card-item {
width: 400px;
height: 250px;
margin: 20px 25px;
border-radius: 0 !important;
box-shadow: 0 0 10px 0 rgba(0, 0, 0, .5);
display: inline-block;
overflow: hidden;
}
::-webkit-scrollbar {
width: 14px;
height: 14px
}
::-webkit-scrollbar-thumb {
height: 6px;
border: 4px solid #002856;
background-clip: padding-box;
border-radius: 12px;
background-color: #002856
}
::-webkit-scrollbar-button {
width: 0;
height: 0;
display: none
}
::-webkit-scrollbar-track {
border: none;
border-radius: 12px
}
JavaScript
/* var mousewheelevt=(/Firefox/i.test(navigator.userAgent))? "DOMMouseScroll" : "mousewheel" //FF doesn't recognize mousewheel as of FF3.x
if (document.attachEvent) //if IE (and Opera depending on user setting)
document.attachEvent("on"+mousewheelevt, function(e){console.log('Mouse wheel movement detected!')})
else if (document.addEventListener) //WC3 browsers
document.addEventListener(mousewheelevt, function(e){console.log('Mouse wheel movement detected!')}, false)
*/
function rotateimage(e){
var evt=window.event || e //equalize event object
var delta=evt.detail? evt.detail*(-120) : evt.wheelDelta //delta returns +120 when wheel is scrolled up, -120 when scrolled down
function scrollingRight() {
$('.card-panel').animate({
scrollLeft: '+=' + ($( '.card-panel' ).width() )
}, 500);
}
nextslideindex=(delta<=-120)? nextslideindex+1 : nextslideindex-1 //move image index forward or back, depending on whether wheel is scrolled down or up
nextslideindex=(nextslideindex<0)? myimages.length-1 : (nextslideindex>myimages.length-1)? 0 : nextslideindex //wrap image index around when it goes beyond lower and upper boundaries
slideshow.src=myimages[nextslideindex]
if (evt.preventDefault) //disable default wheel action of scrolling page
evt.preventDefault()
else
return false
}
var mousewheelevt=(/Firefox/i.test(navigator.userAgent))? "DOMMouseScroll" : "mousewheel" //FF doesn't recognize mousewheel as of FF3.x
if (slideshow.attachEvent) //if IE (and Opera depending on user setting)
slideshow.attachEvent("on"+mousewheelevt, rotateimage)
else if (slideshow.addEventListener) //WC3 browsers
slideshow.addEventListener(mousewheelevt, rotateimage, false)