Most websites have some sort of space dedicated solely to displaying the 'Latest News'. In fact, this is so common, that most content management systems by default reserve a good chunk of landscape for exactly this purpose. But what if you're limited in screen space, or you just want to cut down on clutter? This article will describe an attractive way to tuck the news into one neat little scrolling box. Enjoy!
Creating a Scrolling News Panel - Conclusion (Page 4 of 4 )
This is a somewhat simplified version of the scroll function to get you started. Now don't let that scare you, it may suit your needs perfectly! Just beware that you'll have to establish an exact size for the news div, and that will probably be determined by the amount of content contained within. This will work absolutely fine if you've hard-coded the news in. Whenever you change the news, you can change the global variables to increase or decrease the height of the div. If you don't, you'll end up cutting off some of the news, or scrolling through enormous amounts of whitespace.
However, where you might need to elaborate on this code, is in the case of a dynamic news engine, such as with Mambo, or any other CMS. Here you're loading news content on the fly, and randomly at that. You don't know what the size will be, and it would be a difficult discipline to maintain a standard amount of content in your news blurbs.
So what you might want to do is store the news in a hidden form element. You can then determine approximately how much space you'll need to display it by using the .length property. Once you've set the height of the div, you can then dump the content into it with the ever-useful '.innerHTML' property. This will give you the degree of flexibility you need. Of course, you may come up with your own crafty solution to this problem, so once again feel free to share with all in the forum!
However you decide to use this, I almost guarantee you will enjoy it, as will those browsing your website. You can add in funky functionality, like letting them stop the scrolling to read with a mouseover, or whatever else you can come up with! Have fun!
By the way, here's all the code in one chunk, to save you a lot of copying and pasting. (I know, I know, I'm very considerate. Also humble, damn it.)
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.