Click here to Skip to main content
Click here to Skip to main content

A simple ticker with jQuery

By , 19 Nov 2012
 

Introduction

This is a very simple scroller script that can be added to any HTML page. This Example has been tested and is compatible in IE, Netscape, Firefox, and Opera browsers.

Background

This example is being done using the jQuery framework.

Using the code

HTML Structure
<div id="tickerwrapper">
    <div class="container">
        <ul>
            <li>1 </li>
            <li>2 </li>
            <li>3 </li>
            <li>4 </li>
            <li>5 </li>
            <li>6 </li>
        </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{background:#ccc;height:31px;overflow:hidden;width:150px;} 

JavaScript code

var containerheight = 0;
var numbercount = 0;
var liheight;
var index = 1;

function callticker() {    
    $(".container ul").animate({
        "margin-top": (-1) * (liheight * index)
    }, 2500);
    if (index != numbercount - 1) {
        index = index + 1;
    }
    else {
        index = 0;
    }
    timer = setTimeout("callticker()", 100);
}
$(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()", 100);
}); 

View this example

Click here 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Raghav Nayak
Web Developer
India India
Member
I am UI Developer having 4 years of Experience.
Proficient in HTML , CSS and Javascript/Jquery.
 

Hobbies : Blogging, Games, Movies
 
You can connect me at below social Sites :
Facebook : http://facebook.com/raghavendra.nayak1
Twitter : https://twitter.com/raghu_1987
 
My Blog: http://www.webbycircle.blogspot.com

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionNumber TickerprofessionalLink Worx Seo23 Apr '13 - 3:47 
Was looking for a way to add a ticker for daily updates to where classes are being held for my client othter than the calendar I created for the client and came across this nice little snippet. Think I just might use it with some minor style adjustments.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130513.1 | Last Updated 19 Nov 2012
Article Copyright 2012 by Raghav Nayak
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid