Before Start
This is a simple content display ticker. We can use it for news/quote/testimonial ticker display. Last week I wanted to give a quote ticker in a website. As usual I was looking for Query News Ticker and gone through some. Finally I have decided to make a simple own script, tried and it works fine.
HTML – Understanding the Layout
Decide a box to display content and give an id, say id=”ticker”
<div id="ticker"></div>
JS – Add Jquery core and a simple ticker script
Add the Jquery core as usual. Then the script is simple.
Step 1: Set the content array (It can be HTML)
Step 2: Call the recurring function
Step 3: In the recurring function change the content of the div in some time interval
Step 4: Don’t forget to reset i value at end of the array
After some modification, the code looks like…
<script type="text/javascript" src="jquery.js"></script> $(document).ready(function () { createTicker(); }); function createTicker(){ //set the quotes array tickerItems = new Array( '"There are no great men, only great challenges that ordinary men are forced by circumstances to meet."<br/><b>William F. Halsey</b>', '"Man is only truly great when he acts from his passions."<br/><b>Benjamin Disreali</b>', '"The price of greatness is responsibility."<br/><b>Winston Churchill</b>', '"To achieve great things we must live as if we were never going to die."<br/><b>Marquis de Vauvenargues</b>' ); i = 0; tickerIt(); } function tickerIt(){ if( i == tickerItems.length ){ i = 0; } //change without effect //$('#ticker').html(tickerItems[i]); //change with effect $('#ticker').fadeOut("slow", function(){ $(this).html(tickerItems[i]).fadeIn("slow"); i++; }); //repeat setTimeout("tickerIt()", 5000); }
Thanks for the tutorial, looks nice and clean.
Is there an easy way to refresh the contents of the array with new itmes in a given interval? I’d like to display things from my database and add in newer items as they get posted
Hi Baj,
Without ajax it is very easy.
Fill the tickerItems array from the database. It will work.
Then, by ajax we have to something more. Will try to post while free.
Thanks.
That’s what I’m doing now (populating the array from a database), so that’s working great 🙂 Thanks for the answer, I’ll be hanging around in case you come up with something regarding the last bit
Thank you so much Beschi!
I tried other scripts but so far yours is the most robust one! Thank you again for sharing! 🙂
i love this but how do i populate the array from database?Please can someone help?
hi
how we fill the ticker items with database value.
Code for PHP-Mysql updated with the post.
Please check and reply.
Where it is? Please suggest me
hey good good it works super
Can i also make it work to put the text like ‘There are no great men, only great challenges that ordinary men are forced by circumstances to meet.’ in the html section? because i want to add a blockquote to it so the text is styled in the block quote’s style
Realy simple! extact wthat i was looking for!
Thanks!
its very good article.tnx
Thank you – looked at a few but this was the best!!
i want to display content from database could you help me with the code
I want to display content from database. Can you please suggest me the code or link to refer
With havin so much written content do you ever run into any issues of plagorism or copyright violation? My website has a lot of completely unique content I’ve either authored myself or outsourced but it seems a lot of it is popping it up all over the web without my permission. Do you know any ways to help prevent content from being stolen? I’d truly appreciate it.