I am in need of assistance as I lack the necessary expertise in ReactJs to transform this design. Currently, it is written in Jquery but I would like guidance on how to recreate it in ReactJs. Specifically, I want the left div with the topic for each row to remain sticky when scrolling horizontally. It is important that I do not rely on the jquery library anymore; I aim to implement this purely in react using typescript or emotion 10 or a combination of both.
Any help or suggestions would be greatly appreciated!
Here is the JSFiddle link for reference
Snippet of HTML Code:
<div class="main">
<div class="row">
<div class="sticky">
<div>First1</div>
...
</div>
<div class="content">
<div>row content</div>
...
<div class="content">
<div>row content1</div>
...
<div class="content">
<div>row content1</div>
</div>
</div>
Preview of CSS Code:
.main {
background-color:blue;
overflow: scroll;
height: 200px;
width: 400px;
}
.row {
height: 50px;
clear: both;
width: 1000px;
position: relative;
padding-left: 150px;
box-sizing: border-box;
}
.sticky, .content {
float: left;
width: 150px;
border: 1px solid black;
}
.sticky {
background-color: red;
position: absolute; left: 0; top: 0;
}
.content{
background-color: green;
}
To achieve horizontal scrollbar similar to the fiddle, here is an example of jQuery code:
$('.main').scroll(function(){
$(this).find('.sticky').css('left', $(this).scrollLeft());
});