I am trying to scroll text (list elements actually) from right to left.
Here is HTML code
<div id="slider-txt">
<ul>
<li class="islide">text 1</li>
<li class="islide">text 2</li>
</ul>
</div>
my CSS
#slider-txt
{
position:relative;
width: 590px;
}
#slider-txt ul
{
list-style-type: none;
position: absolute;
margin: 0px;
padding: 0px;
}
#slider-txt ul li
{
text-align: right;
}
and the jQuery
var box = $('#slider-txt');
if (box.length == 0) {
return;
}
var ul = box.find('ul');
var li = $('#slider-txt').find('li');
var liWidth = box.width();
var ulWidth = liWidth * li.length;
li.css('width', liWidth);
ul.css('width', ulWidth);
li.css('display', 'inline-block');
var liElement = 0;
function slideNxt() {
liElement++;
if (liElement == li.length) {
liElement = 0;
}
var curLeftPos = ul.css('left').split('px')[0];
var newLeftPos = -(liElement * liWidth);
ul.animate({ left: newOffset + 'px' }, { duration: 'slow', easing: 'swing' });
}
setInterval(slideNxt, 2000);
The above code swings the list items right to left and left to right in loop. The inline-block property set on list items don't seem to work as expected (List items are displayed one below another). Also I want the list item to get hidden if it goes out of the box (div#slider-txt) width, which is not happening.
Can you please help me fixing these issues? Thanks...