Free news scroll script
Here is a basic script for a free news scroll in JavaScript and HTML:
<!-- HTML -->
<div id="news-scroll">
<ul id="news-list"></ul>
</div>
<!-- JavaScript -->
<script>
// News data (replace with your own data)
const newsData = [
{ title: "News Item 1", text: "This is the text of news item 1." },
{ title: "News Item 2", text: "This is the text of news item 2." },
{ title: "News Item 3", text: "This is the text of news item 3." },
// Add more news items here...
];
// Function to generate the news list
function generateNewsList() {
const newsList = document.getElementById("news-list");
newsList.innerHTML = "";
newsData.forEach((item) => {
const listItem = document.createElement("li");
listItem.innerHTML = `
<h2>${item.title}</h2>
<p>${item.text}</p>
`;
newsList.appendChild(listItem);
});
}
// Function to scroll the news list
function scrollNewsList() {
const newsList = document.getElementById("news-list");
newsList.scrollTop = newsList.scrollHeight;
}
// Call the functions to generate and scroll the news list
generateNewsList();
setInterval(scrollNewsList, 5000); // Scroll every 5 seconds
</script>
This script creates a news list with a list of news items, and then uses JavaScript to generate the list and scroll it every 5 seconds. You can customize the script by adding more news items, changing the scrolling interval, or modifying the HTML and CSS to fit your needs.
Here's a breakdown of the script:
- The
newsData
array contains the news items, with each item having atitle
andtext
property. - The
generateNewsList()
function generates the news list by creating a list item for each news item in thenewsData
array, and then appending it to thenews-list
element. - The
scrollNewsList()
function scrolls thenews-list
element to the bottom, so that the latest news item is always visible. - The
setInterval()
function calls thescrollNewsList()
function every 5 seconds, so that the news list scrolls continuously.
You can add more news items to the newsData
array, and modify the generateNewsList()
and scrollNewsList()
functions to fit your needs. You can also add CSS styles to customize the appearance of the news list.