Display Random Text in Your Website Using Savvy.UI

Posted on the September 4th, 2008 under JavaScript, Programming, Savvy.UI, Tutorial by Zaki

What your opinion to the random text appearing at the upper right corner of this blog? Would like to have one too? Savvy.UI JavaScript Library has made it easy for you to display message or note without interfering the user view of the application using Js.widget.message object.

Initializing The Object

Declaring the Js.widget.message object is practically simple, all you need to do is include the Savvy.UI script and the Cascading Style Sheet file included in the package and add this line.

Js.simplify(); // this is optional if you prefer to use $(), otherwise Js()
 
$(document).ready() {
	Js.widget.message.init();
});

Random Text Script

Creating the random text script is roughly simple, all you need to do is put all possible text/quote as an array and display it randomly using Math.random and Js.widget.message.add(). Here how I did it.

$(document).ready(function() {
	var note = function() {
		var texts = [
			"Welcome to my blog", 
			"Howdy there",
			"Looking for something?",
			"Drop a comment while you at it...", 
			"Hope you find the information here useful", 
			"Contact me if you have any enquiry", 
			"Do you have any freelance work for me?", 
			"I just love PHP and JavaScript, do you?",
			"My name is Mior Muhammad Zaki, what's yours?"
		];
		var i = Math.floor(Math.random()*texts.length);
 
		// now let display the selected text
		Js.widget.message.add({text: texts[i]});
	};
	note();
	setInterval(note, 10000); // give it 10 second interval delay
});
View Source View Demo

One Response to 'Display Random Text in Your Website Using Savvy.UI'

Subscribe to comments with RSS or TrackBack to 'Display Random Text in Your Website Using Savvy.UI'.
  1. No comment at the moment.
  1. [...] tutorial is a continuation of my previous tutorial Display Random Text in Your Website Using Savvy.UI but instead of random text this time we will display your latest Twitter Status. The tutorial is [...]

Leave a Reply
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">