Jquery breaking news ticker
A breaking news ticker using jQuery! Here's a simple example to get you started:
HTML
<div id="breaking-news-ticker">
<ul id="ticker-list">
<!-- news items will be appended here -->
</ul>
</div>
CSS
#breaking-news-ticker {
position: relative;
width: 300px; /* adjust to your desired width */
height: 30px; /* adjust to your desired height */
overflow: hidden;
background-color: #f0f0f0;
border: 1px solid #ccc;
padding: 5px;
font-size: 14px;
font-family: Arial, sans-serif;
}
#ticker-list {
list-style: none;
margin: 0;
padding: 0;
position: relative;
}
#ticker-list li {
display: inline-block;
margin-right: 10px;
padding: 5px;
background-color: #fff;
border: 1px solid #ccc;
border-radius: 5px;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
}
#ticker-list li:last-child {
margin-right: 0;
}
JavaScript (using jQuery)
$(document).ready(function() {
// define the news items array
var newsItems = [
"Breaking: New study reveals...",
"Stock market plummets...",
"Weather alert: Tornado warning issued...",
"Breaking: Celebrity news...",
// add more news items here
];
// create the ticker list
var tickerList = $("#ticker-list");
// append news items to the ticker list
$.each(newsItems, function(index, item) {
tickerList.append("<li>" + item + "</li>");
});
// set the ticker animation
var tickerWidth = tickerList.width();
var tickerListItems = tickerList.children("li");
var tickerListItemsLength = tickerListItems.length;
var tickerInterval = setInterval(function() {
tickerListItems.eq(0).animate({
left: -tickerWidth
}, 1000, function() {
$(this).appendTo(tickerList);
});
}, 5000); // update every 5 seconds
// stop the ticker animation when the user hovers over the ticker
$("#breaking-news-ticker").hover(function() {
clearInterval(tickerInterval);
}, function() {
tickerInterval = setInterval(function() {
tickerListItems.eq(0).animate({
left: -tickerWidth
}, 1000, function() {
$(this).appendTo(tickerList);
});
}, 5000);
});
});
This code creates a simple breaking news ticker that displays a list of news items. The ticker animation moves the news items from right to left, and when the last item is reached, it wraps around to the beginning. The animation is paused when the user hovers over the ticker, and resumes when the user moves away.
You can customize the appearance and behavior of the ticker by modifying the CSS and JavaScript code. For example, you can change the animation speed, add more news items, or modify the layout of the ticker list.