I have spent the last two days looking for a simple javascript or jquery code for this. I want to incorporate a horizontal scrolling div using javascript or jquery to display i
You can just use code like this:
function FixMargin(left) {
$(this).css("left", left);
}
$(document).ready(function () {
$('#rightbutton').click(function () {
var left = parseInt($("#bitToSlide").css('left'), 10);
$("#bitToSlide").animate({ left: left - pageWidth }, 400, FixMargin(left - pageWidth));
});
$('#leftbutton').click(function () {
var left = parseInt($("#bitToSlide").css('left'), 10);
$("#bitToSlide").animate({ left: left + pageWidth }, 400, FixMargin(left + pageWidth));
});
}
where your html looks like this:
and your css looks like this:
.slide
{
position:relative;
overflow:hidden;
height:365px;
width:597px;
margin:1em 0;
background-color:#E9ECEF;
border:0px
}
.slide .inner
{
position:absolute;
left:0;
bottom:0;
height:365px;
padding:0px;
background-color:#E9ECEF;
color:#333
}
I wrote the above a really long time ago - so you probably want to update it a bit (replace the table's with div's for example) but it works.
You obviously need the two buttons on there as well