In this tutorial I am going to tell you how we can transform some explanation and available basic HTML into an attractive news ticker that fluently scrolls its contents. News tickers can be horizontal as well as vertical today I am going to create a vertical ticker. Please have a look.
In the example i am making a news scroller which contains plain text. You can put any content that you want, it can be images, or links, or text. I'll be using jQuery with little HTML along with CSS. Let’s make a start.
Step1: Html goes like this
<!DOCTYPE html>
<html>
<head>
<title>jQuery news_ticker</title>
<body>
<div class="news_ticker">
<h3>Latest News</h3>
<ul id="news_ticker">
<li>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum</li>
<li>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.</li>
<li>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure</li>
<li>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable</li>
<li>The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.</li>
</ul>
</div>
</body>
</html>
Step 2: CSS
<style type="text/css">
.news_ticker {
background-color: #fba41a;
border: 1px solid #000;
border-radius: 5px;
box-shadow: 0 0 5px #000;
height: 100%;
overflow: hidden;
text-align: left;
width: 100%;
}
.news_ticker h3 {
padding: 0 0 10px 10px;
border-bottom: 1px solid #000;
}
ul {
list-style: none;
padding: 0;
margin: 0;
font-style: italic;
}
ul li {
list-style: none;
height:50px;
padding:7px;
border-bottom: 1px solid #000;
}
</style>
Step3: Jquery
<script type="text/javascript">
function news_ticker() {
$('#news_ticker li:first').slideUp(function() {
$(this).appendTo($('#news_ticker')).slideDown();
});
}
setInterval(news_ticker, 3000);
</script>
Here I am using the slideUp() it basically slides-up the selected elements.
Syntax of slideUp method is
$(selector).slideUp(speed,easing,callback)
- speed - It is optional you can give the speed of the slideUp effect as you want. It has to be in milliseconds.
- easing- It is optional and it is the speed of the element in different points of the animation.
- callback- It is optional. Callback is the function that has to be executed after the slideUp() method is completed.
Now I am appending the current <li> to the div and then applying the slideDown(). slideDown() it basically slides down the selected elements.
syntax of SlideDown() is
$(selector).slideDown(speed,easing,callback)
- speed - It is optional you can give the speed of the slideDown effect as you want. It has to be in milliseconds.
- easing- It is optional and it is the speed of the element in different points of the animation.
- callback- It is optional. Callback is the function that has to be executed after the slideDown() method is completed.
Here is the working demo: https://jsfiddle.net/cLhaosyz/
0 Comment(s)