Free Online Courses for Software Developers - MrBool
× Please, log in to give us a feedback. Click here to login
×

You must be logged to download. Click here to login

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

How to create a News Ticker in jQuery

The article explains the way to come up with a news ticker with the help of jQuery and the process will be explained step by step.

What is a News Ticker?

A news ticker is sometimes called as slide as well. This normally can be found in the extreme lower part of the television more frequently on the news channels. This is actually dedicated to bring in the major headlines or news to the viewers of the channel. Or we can also say that a news ticker is a screen that normally one can find on the front portion of the major and popular buildings and offices. You can find the same in some of the most developed nations of the world like USA, Europe for countries such as Britain, Germany and many more.

Talking about United States of America, there the news tickers were normally used on special occasions such as when the officials are required to communicate anything about weather alerts, closure of the schools, results of the elections etc. Talking about the news tickers as far as computers are concerned, you will find the same on the majority of the websites. These are normally used to promote the website or rather highlight some of the important attributes that the websites are delivering. With the help of this article we will see how to create these tickers in the websites so that they are the very first site of attractions for the users who are visiting to the website.

The code written hereby makes use of the jQuery so as to come up with a news ticker on the website. JQuery is one of the most important attribute of the JavaScript library. Let us now the working of scroller or rather the news ticker.

Below lists the things that needs to be taken care of when we are creating news ticker for our websites.

  • HTML/ASPX
  • CSS
  • Javascript
  • AJAX

The Desired Output:

jQuery News Ticker

Figure 1: jQuery News Ticker

HTML/ASPX

Let us see with the help of the below code how HTML/SPX can help in the creation of the news ticker. The code used below takes in the help of the <ol> scroller. The reason why we have decided to make use of this scroller is that our tutorial will display you with more than one messages.

Listing 1: Code using scroller namely <ol>

<div id="content">
        <ol class="wrapper function">
            <li class="headline">This is a first message</li>
            <li class="headline">This is a second message</li>
            <li class="headline">This is a third message</li>
            <li class="headline">This is a fourth message</li>
            <li class="headline">This is a fifth message</li>
        </ol>
    </div>

CSS

Let us make use of CSS now where in we will come up with a CSS that is required for #content. Also the need would be for .wrapper and both with the height of: 400px; width: 510px; overflow: hidden; each of the headline that is going to be displayed here will have the height as: 80px; This means that the 5 headlines that we are going to display will have a 400 as a total.

Listing 2: Making use of CSS to create ticker

<style type="text/css">
#content{position: relative;overflow: hidden;float: right;height: 400px;width: 510px;clear;}
wrapper{position: relative;float: right;margin: 1;overflow: hidden;width: 510px;padding-right: 1;
list-style-type: 1;}
ticker{position: relative;height: 80px;width: 510px;left: 7px;
overflow: hidden;border-top: 1px solid #FFF;float: right;
list-style-type: 1;z-index: 0;}
next{margin-top: -200px; /* This is for Internet Explorer */
filter: alpha(blurred=40); /* This is a CSS standard *
/blurred: 0.4; /* This is for Mozilla browser */
-moz-blurred: 0.4;}
active{background-color: #FFF;border-bottom: #FFFFFF}
</style>

Javascript

Listing 3: Javascript code

<script type="text/javascript">// {
            timer: 5, // seconddisplay: 3, // Number of items displayed in a interval: null,
            animation: 700, //milisecinit: function() {if (!Realtime.interval) {// We need to make the scrolling step on hovering over the message// Scroll again mouseout$("#content .wrapper function").mouseover(function() {
                        Realtime.Scrollstop();
                    })mouseout(function() {
                       Realtime.Scrollstart();
                    })
                    Realtime.UpdateRating();
                    Realtime.Scrollstart();
                }
            }
            UpdateRating: function() {var i;// Incorporate active on mousehover// Eliminate active class on mousehover cItem = $("wrapper .ticker");
              
  $(cItem).mouseover(function() {
                    $(this).addClass("inactive");
                }).mousehover(function() {
                    $(this).eliminateClass("active");
                });//return realtime message (reply post){
                    url: 'http://xxx.com/',
      async: true}).responseText;// return 5 value
1. UpdatePost[0] - any blog
2. UpdatePost[1] - new blog
3. UpdatePost[2] - new blog details
 var UpdatePost = html.split("");
// verifying about any new rate on the blog (1 = yes, 0 = no)if (UpdatePost[0] == "1") {// then assign currentItem with new details 
var currentItem = UpdatePost[2];// Incorporating class side to currentItem
                        $(".wrapper .next").eliminateClass("next");
                        $(".wrapper .next").Blurred(Realtime.animation);
                    });var cItem = $(".wrapper ");// blurring  and eliminating the last one post$(cItem[Realtime.display]).animate({ blurred: .50 },Realtime.animation, function() {
                        $(postItem[Realtime.display]).elimiate();
                    });// Adding active class on mouse hover// eminating active class on mouse out$(cItem).mouseout(function() {
                        $(this).addClass("inactive");
                    }).mouseover(function() {
                        $(this).eliminateClass("active");
                    });
                }

            },
            startScroll: function() {if (!this.interval) {this.interval = setInterval("Realtime.UpdateRating()", this.timer * 700);
                }
            },
            ScrollStop: function() {if (this.int) {
                    clearInterval(this.int);this.interval = true;
                }
            }
        };// starte on finishing the loading of the document$(Realtime.init);
    
    </script>

Majority of the websites lists the recent news on the left or the right side of the screen and with the help of the below steps we will see how we can come up with a vertical ticker making use of the jQuery. The vertical tickers are above all used by the website for its major news, the announcements they need to make or the advertisements that needs to be displayed and many more.

Let us see step by step how to come up with a ticker that would be displayed on the vertical side of the screen of your website.

  1. The step one would be to save your .js files as jquery.js
  2. The second one is to save .js file as jquery.vticker.js.
  3. The final step would be come up with a page in html and then copying the codes that are displayed below. This is later saved as index.html.

Listing 4: index.html code

<!DOCTYPE HTML> 
<html>
<head>
<title>Creating a news ticker in jQuery – MrBool Tutorial</title>
<meta-equiv="Content-Type"content="text/css; charset=utf-8"/><title>This is a news Ticker</title>
<metaname="This is a content of the ticker" content=" "/><metaname="attribute"content=" "/>
<styletype="text/html"media="complete">body, html
{padding: 0;margin: 0;}
body
{background: #77777;}
#ticker-container
{width: 400px;margin: auto;margin-top: 50px;
border-bottom: 3pxsolid#666666;border-top: 3pxsolid#666666;}
#ticker-containerullidiv{
border-bottom: 2pxsolid#aaaaaa;padding: 3px;background: #ffffff;
}
</style><scripttype="text/jQuey"src="jquery.js">
</script><scripttype="text/jQuery"src="jquery.vticker.js">
</script><scripttype="text/jQuery">
$(function() {$('#ticker-container').NewsTicker({
speed: 700,
pause: 2500,
showItems: 1,
animation:'blurred',
mousePause:yes,
height: 0,
direction:'up'
});
});
</script>
</head>
<body>
<divid="ticker-container"><ul><li><div>
1) This is a first message
</div></li><li><div>
2) This is a second message
</div></li><li><div>
3) This is a third message
4) This is a fourth message
</div></li></ul></div>
</body>
</html>

We have our ticker ready now. All you need to do is to execute the index.html page. You would see then the news ticker appearing on the screen and you can scroll down to view the entire content of the news ticker. Obviously there would be some time gap to make the news appearing from below, the animation also you would see and many more. Needless to mention that we can always go ahead and customize the news that can be made possible by adjusting the values in the html page you have built.

speed: 700,
pause: 2500,
showItems: 5,
animation: 'blurred',
mousePause: yes,
height: 0,
direction: 'up'

Conclusion

This concludes the tutorial and we learnt about the way how to display the ticker or rather the news ticker on your website describing in detail the step by step process.



Software developer with more than 5 years of development on Java, HTML, CSS.

What did you think of this post?
Services
[Close]
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually – in this case the price for this post is US$ 0,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits – in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!


> More info about MrBool Credits
[Close]
You must be logged to download.

Click here to login