Get Certified on your expert knowledge

Brainbench grant you full access to assessments and certifications covering over 600 skills in demand for today's marketplace.
Visit the site and get certified. Click Here to take some FREE tests.

Monday, June 11, 2012

How to make simple number ticker with jquery

HTML Structure
<div id="tickerwrapper">
    <div class="container">
        <ul>
            <li>1li>
            <li>2li>
            <li>3li>
            <li>4li>
            <li>5li>
            <li>6li>
        ul>
    div>    
div>


CSS 
*{padding:0;margin:0}
ul li{list-style:none}
#tickerwrapper{padding:20px;width:150px}
#tickerwrapper ul li{padding:5px;text-align:center}
#tickerwrapper .container{width:150px;height:31px;overflow:hidden;background:#ccc;}


Javascript  Code
var containerheight = 0;
var numbercount = 0;
var liheight;
var index = 1;
$(document).ready(function() {
    numbercount = $(".container ul li").size();
    liheight = $(".container ul li").outerHeight();
    containerheight = $(".container ul  li").outerHeight() * numbercount;
    $(".container ul").css("height", containerheight);
    var timer = setTimeout("callticker()", 3600);
});


function callticker() {
        $(".container ul").animate({
            "margin-top": (-1) * (liheight * index)
        } , 2500, "easeOutElastic");


        if (index != numbercount - 1) {
            index = index + 1;
        }
        else {
            index = 0;
        }
        timer = setTimeout("callticker()", 3600);
    }


See the Demo here

No comments:

Post a Comment