Categories

Request Script

Donate

Javascript Scroller

Whoever invented the <marquee> tag had poor execution, but the right idea. Sometimes it’s nice to have content fit inside a box smaller than itself. Scrollbars can be ugly at times, so a Javascript scroller can be a clean way to implement this.

This is a script I actually made a long time ago for a client, but recently expanded upon it for another client and decided to make it a general, reusable script.

Example: Here
Javascript: Here

Basically it’s just an array of elements in a smaller container and it scrolls left or right and at different speeds depending on where the mouse is.

After the page loads, to make a container into a scroller, call the initScroller function passing it a json object with the following properties:

  • id required – The id of the HTML element to use.
  • width required – The width of the HTML element specified by id.
  • height required – The height of the HTML element specified by id.
  • speed Default: 1 – The max speed at which to scroll. This number represents max pixels per “frame,” but basically the higher, the faster.
  • neutral Default: 0.25 – This is the amount of neutral space, or area which does not cause motion. The higher it is, the wider this zone is. The minimum value is 0 (no neutral zone) and the max value should be speed. Technically, its the speed under which for the scroller to not move at all.
  • switchDirection Default: false – By default the scroller scrolls to the right when the mouse is on the right, and left when the mouse is on the left. Setting this value to true makes the opposite happen.
  • framerate Default: 50 – The higher the value, the faster the animation interval is. Increasing this value will make for smoother but more CPU intensive animation and reducing the value should have the inverse effect. Note that changing this value has side effects for the speed of the scroll. The default value should suffice in most situations.

As shown on the example, multiple scrollers can be on one page without any variable interference.

Do note that the script should be called after the page has been rendered. Because of this, the container may need some CSS is make it “pretty” while the page is still loading such as the dimensions andoverflow: hidden, depending on the other styles in the document.

Site Launched

The site is launched. Yay. I’m still working on the design and contemplating functionality. This is what I’m planning though for the website:

  • A blog for my programming-related thoughts and problems I’ve run across and solved which others may also run into sometime
  • A collection of scripts I’ve written freely available to anyone who wants to use them, along with a detailed explanation of how to use them with examples. User comments are welcome to find bugs or explain the script in a way I may assume is easy (since I wrote it)
  • A “request-a-script” feature where one can request development of a custom script. This I would actually charge for. Once the script was developed and paid for, it would be added to the freely available scripts mentioned above.

Basically, I’d like it to be a combination of a programming blog and a website like dynamicdrive.com.

Some background on me and how I program. I don’t like the idea of paying for software, however, I DO believe in paying for someone to develop software. This is exactly how I plan to run this site. As soon as a custom script is paid for for development, it’s free.

I also am super elitist and write only custom scripts. I don’t use tools like mootools or jQuery. I know that this make it so development takes more time, but I think custom code is a lot cleaner, efficient, and flexible than when using libraries. Plus, I feel like programming from scratch gives a much better learning experience, and I am still in college.

Anyway, I’ll be posting a few scripts I already have soon, right after I finish the site’s design and whatnot.