Scripting language is of two types, client side scripting and server side scripting language. The difference between the client side scripting and server side scripting language is that client side scripting programs could be executed on any client computer and server scripting programs could be executed only on the server. Javascript and Vbscript are client side scripting languages. For example, if there is a contact form of the website with few fields. Email is one of the fields in that contact form so now if a user enters some number only or character only or email in invalid format and send to server then the server will have to process an email in invalid format. To process, the server will check and verify the format of the email and when it will find that email is in invalid format then it will tell back to client computer that the email is invalid format so enter the email in correct format. This was only one client computer that send the wrong data but when a website is running globally, there might be thousands of users logged on at the same time and what would be happen to server if all clients send wrong data at the same time. To prevent this mishappening, it would be better if the format of email is checked at the client computer only and if the email is in the correct format then only it is send to the server for processing.
Javascript is a popular scripting language and has been in use for many years. Days when flash was not popular and not used by many designers, Javascript was used to give nice effects to webpages. Javascript is still better than flash in minor designing needs because javascript pages are ranked better than flash pages in search engines. Some of the powerful features of this scripting language are described as below.
1. Nearly all browsers support javascript and you dont need to install any plugin to execute javscript codes whereas to run flash pages, flash plugin should be installed in your browser.
2. Javascript is same as any other functional programming language that can handle objects also. Variables could be declared and functions could be created. Property like inheritance of OOPS is also supported in Javascript but it is not same as inheritance in Java. Javascript programs be executed on both server and the client.
Javascript codes enhance your web design skills. Now to know more about javascript, learn these 20 Javascript codes to make your web design look excellent.
1. Javascript alerts
Javascript alerts are very important and used to display a message or warning to the user in a dialog box. Now see this code that will display an alert message on a webpage.<script language=javascript>
alert('My name is John);
</script>
2. Opening New Window
A new window can be opened in any page using Javascript code. There are two ways to open a new page. A new page can be made to open by clicking a link or by clicking a button. Now see both these codes below.<Script Language="JavaScript">
function load() {
var load=
window.open('http://www.webdesignerdepot.com','','scrollbars=no,menubar=no,height=600,width=
800,resizable=yes,toolbar=no,location=no,status=no');
}
// -->
</Script>
<a href="javascript:load()">Open Window</a>
<form>
<input type="button" value="Open Window"
onclick="window.open('http://webdesignerdepot.com ')">
</form>
3. Set as Users homepage
Many sites provide a button in their webpage and if you click on that button then that site will be set as your homepage that means whenever you open your browser that site will be opened automatically. You can also provide a button in your webpage that if clicked on the client computer then your site will be made as home page on the client computer. See these lines of code below.<FORM>
<INPUT TYPE="button" VALUE="Make This Site Your Home Page"
onClick="this.style.behavior='url(#default#homepage)'; this.setHomePage(' http://webdesignerdepot.com');">
</FORM>
4. Close Window
In many sites you must have seen that when you logout from your account then a message box is displayed asking to close the window and if you click “OK” then the browser is closed. This is done to avoid reuse of that window. You can do so in your website also just by placing one line code in your page wherever you want to display the message. See the line of code below.<a href="javascript: self.close()">Close Window</a>
Self.close closes the window. One more function is used for the same purpose that is Window.close.5. Statusbar Message
In some sites you must have seen some message displayed in statusbar. Its not a difficult job and you could also do this just by placing few lines of code in your html document. See the lines of code below.<SCRIPT language="JavaScript">
var current = 0
var x = 0
var speed = 100
var speed2 = 100
function initArray(n) {
this.length = n;
for (var i =1; i <= n; i++) {
this[i] = ' '
}
}
typ = new initArray(4)
typ[0]="My name is Nitesh."
typ[1]="I am a freelancer."
typ[2]="I am a programmer."
typ[3]="Article writing is my hobby."
function typewrite() {
var m = typ[current]
window.status = m.substring(0, x++) + ""
if (x == m.length + 1) {
x = 0
current++
if (current > typ.length - 1) {
current = 0
}
setTimeout("typewrite()", speed2)
}
else {
setTimeout("typewrite()", speed)
}
}
typewrite()
// -->
</SCRIPT>
6. Clock in Status bar
You can also display clock in status bar as you displayed message in the previous code. To do so use the lines of code written below.<script Language="JavaScript">
var timerID = null;
var timerRunning = false;
function stopclock (){
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
function showtime () {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()
var timeValue = "" + ((hours >12) ? hours -12 :hours)
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " P.M." : " A.M."
window.status = timeValue;
// you could replace the above with this
// and have a clock on the status bar:
//
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}
function startclock () {
// Make sure the clock is stopped
stopclock();
showtime();
}
// -->
</script>
<BODY onLoad="startclock()">
The function startclock() that is made in the above script can be added in the body tag of your page to display the clock in your status bar.7. Clock in webpage
The above clock was displayed in the status bar only but we may also need to show the clock in webpage. To show the clock in webpage see the code below.<script type="text/javascript">
var imageclock=new Object()
//Enter path to clock digit images here, in order of 0-9, then "am/pm", then colon
image:
imageclock.digits=["c0.gif", "c1.gif", "c2.gif", "c3.gif", "c4.gif", "c5.gif", "c6.gif", "c7.gif",
"c8.gif", "c9.gif", "cam.gif", "cpm.gif", "colon.gif"]
imageclock.instances=0
var preloadimages=[]
for (var i=0; i<imageclock.digits.length; i++){ //preload images
preloadimages[i]=new Image()
preloadimages[i].src=imageclock.digits[i]
}
imageclock.imageHTML=function(timestring){ //return timestring (ie: 1:56:38) into
string of images instead
var sections=timestring.split(":")
if (sections[0]=="0") //If hour field is 0 (aka 12 AM)
sections[0]="12"
else if (sections[0]>=13)
sections[0]=sections[0]-12+""
for (var i=0; i<sections.length; i++){
if (sections[i].length==1)
sections[i]='<img src="'+imageclock.digits[0]+'" />'+'<img
src="'+imageclock.digits[parseInt(sections[i])]+'" />'
else
sections[i]='<img
src="'+imageclock.digits[parseInt(sections[i].charAt(0))]+'" />'+'<img
src="'+imageclock.digits[parseInt(sections[i].charAt(1))]+'" />'
}
return sections[0]+'<img src="'+imageclock.digits[12]+'" />'+sections[1]+'<img
src="'+imageclock.digits[12]+'" />'+sections[2]
}
imageclock.display=function(){
var clockinstance=this
this.spanid="clockspan"+(imageclock.instances++)
document.write('<span id="'+this.spanid+'"></span>')
this.update()
setInterval(function(){clockinstance.update()}, 1000)
}
imageclock.display.prototype.update=function(){
var dateobj=new Date()
var
currenttime=dateobj.getHours()+":"+dateobj.getMinutes()+":"+dateobj.getSeconds() //create
time string
var currenttimeHTML=imageclock.imageHTML(currenttime)+'<img
src="'+((dateobj.getHours()>=12)? imageclock.digits[11] : imageclock.digits[10])+'" />'
document.getElementById(this.spanid).innerHTML=currenttimeHTML
}
</script>
<script type="text/javascript">
new imageclock.display()
</script>
8. Protect Content
Sometimes you need to protect the content of your site from copying. Matrimonial sites such as Jeevansathi.com used to protect the images of their profiles from being copied. You can also do so by using just few lines of code.<SCRIPT language="JavaScript">
var message="Copyright 2009 to www.allaboutwebsite.com. WARNING! All content contained
within this site is protected by copyright laws. ";
function click(e) {
if (document.all) {
if (event.button==2||event.button==3) {
alert(message);
return false;
}
}
if (document.layers) {
if (e.which == 3) {
alert(message);
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
// -->
</SCRIPT>
screenshots or by opening view source.
9. Protect page by Password
The above method can be used only for beginners but cannot stop experienced users so to stop experienced you can protect a page by password. See these lines of code below.<SCRIPT language="JavaScript"><!--
var statusMsg = "Password Protected Area"
function gateKeeper() {
var password = prompt("Password required:", "");
this.location.href = password + ".htm";
}
</SCRIPT>
<A HREF="javascript:gateKeeper()"
onMouseOver="self.status=statusMsg; return true"
onMouseOut="self.status=''; return true"
onClick="gateKeeper(); return false">Open my Home page</A>
10. Close Alert
You can also place close alert on your page. It means that when you close your page then you get close message such as “Good bye”. Read the code below.<BODY onUnload="window.alert(' Good Bye ')">
</BODY>
11. Checking if compulsory field is filled or not
You must have registered in many sites or created email in hotmail, yahoo etc and you must have noticed that registration forms of such sites have some compulsory fields. The compulsory fields are necessary to be filled but what if someone try to register without filling compulsory fields. So there must be some procedure or mechanism to check the compulsory fields of such forms. Javascript provides the facility to write such codes. Read the code below.<script language=javascript>
function fun(){
if(document.form1.name.value==''){
alert('[Please enter your Name]');
document.form1.name.focus();
return false;
}
}
</script>
<form method="POST" name="form1" action="registrationprocess.php" script
language="javascript" onsubmit="return fun();">
<tr>
<td align="right" width="265"><b><span class="form_required">Name:</span></b></td>
<td width="401">
<input maxLength="50" name="name" size="35"></td>
</tr>
</form
12. Matching the value of password and confirm password
Apart from checking the value of compulsory fields, sometimes you may also need to confirm that the value of two fields is same or not. Read the code below.<script language=javascript>
function fun(){
if(document.form1.password.value!=document.form1.confirmpassword.value){
alert('[Please enter same Password]');
document.form1.email.focus();
return false;
}
}
</script>
13. Checking the status of checkbox of page
In the registration form of many sites, there is a checkbox in the last of page before the submit button with the message “Select the checkbox if you agree with the terms and conditions” and user is able to proceed to the next page only after checking this checkbox. You can do this in your page also just by placing few lines of checkbox. Read the code below for checking the status of checkbox.<script language=javascript>
function fun(){
if(document.form1.terms.checked==false){
alert('[You must agree with our terms and conditions]');
document.form1.terms.focus();
return false;
}
}
</script>
14. Checking the value of Email field
In all the registration forms, there is a field email and user may enter wrong value or value in the wrong format in this field. Checking the value of email in the correct format is not an easy task as it was in earlier case because here number of cases are need to be considered. Read the code below.<script language=javascript>
function fun(){
var at="@"
var dot="."
var lat=document.form1.email.value.indexOf(at)
var lstr=document.form1.email.value.length
var ldot=document.form1.email.value.indexOf(dot)
if (document.form1.email.value.indexOf(at)==-1){
alert("Please enter a proper email address\neg. abc@hotmail.com.")
document.form1.email.focus();
return false;
}
if(document.form1.email.value.indexOf(at)==-1 || document.form1.email.value.indexOf(at)==0
|| document.form1.email.value.indexOf(at)==lstr){
alert("Please enter a proper email address\neg. abc@hotmail.com.")
document.form1.email.focus();
return false;
}
if(document.form1.email.value.indexOf(dot)==-1 ||
document.form1.email.value.indexOf(dot)==0 ||
document.form1.email.value.indexOf(dot)==lstr){
alert("Please enter a proper email address\neg. abc@hotmail.com.")
document.form1.email.focus();
return false;
}
if(document.form1.email.value.indexOf(at,(lat+1))!=-1){
alert("Please enter a proper email address\neg. abc@hotmail.com.")
document.form1.email.focus();
return false;
}
if(document.form1.email.value.substring(lat-1,lat)==dot ||
document.form1.email.value.substring(lat+1,lat+2)==dot){
alert("Please enter a proper email address\neg. abc@hotmail.com.")
document.form1.email.focus();
return false;
}
if(document.form1.email.value.indexOf(dot,(lat+2))==-1){
alert("Please enter a proper email address\neg. abc@hotmail.com.")
document.form1.email.focus();
return false;
}
if(document.form1.email.value.indexOf(" ")!=-1){
alert("Please enter a proper email address\neg. abc@hotmail.com.")
document.form1.email.focus();
return false;
}
}
</script>
15. Mouseover Function
Mouseover function can give better look to your webpage in terms ofinstructions or other message. The message or instructions can be shown when the mouse is over the links or button. Read the code below.<a href="/" onMouseOver="alert('My name is Nitesh');return true;">Mouseover Function</a>
In the above code, when you take your mouse over the link “Mouseover Function”, the message
“My name is John ” is displayed.
16. Raining Effect: You can also give raining effect on your webpage. Read the code below.
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var no = 50;
var speed = 1;
var ns4up = (document.layers) ? 1 : 0;
var ie4up = (document.all) ? 1 : 0;
var s, x, y, sn, cs;
var a, r, cx, cy;
var i, doc_width = 800, doc_height = 600;
if (ns4up) {
doc_width = self.innerWidth;
doc_height = self.innerHeight;
}
else
if (ie4up) {
doc_width = document.body.clientWidth;
doc_height = document.body.clientHeight;
}
x = new Array();
y = new Array();
r = new Array();
cx = new Array();
cy = new Array();
s = 8;
for (i = 0; i < no; ++ i) {
initRain();
if (ns4up) {
if (i == 0) {
document.write("<layer name=\"dot"+ i +"\" left=\"1\" ");
document.write("top=\"1\" visibility=\"show\"><font color=\"blue\">");
document.write(",</font></layer>");
}
else {
document.write("<layer name=\"dot"+ i +"\" left=\"1\" ");
document.write("top=\"1\" visibility=\"show\"><font color=\"blue\">");
document.write(",</font></layer>");
}
}
else
if (ie4up) {
if (i == 0) {
document.write("<div id=\"dot"+ i +"\" style=\"POSITION: ");
document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: ");
document.write("visible; TOP: 15px; LEFT: 15px;\"><font color=\"blue\">");
document.write(",</font></div>");
}
else {
document.write("<div id=\"dot"+ i +"\" style=\"POSITION: ");
document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: ");
document.write("visible; TOP: 15px; LEFT: 15px;\"><font color=\"blue\">");
document.write(",</font></div>");
}
}
}
function initRain() {
a = 6;
r[i] = 1;
sn = Math.sin(a);
cs = Math.cos(a);
cx[i] = Math.random() * doc_width + 1;
cy[i] = Math.random() * doc_height + 1;
x[i] = r[i] * sn + cx[i];
y[i] = cy[i];
}
function makeRain() {
r[i] = 1;
cx[i] = Math.random() * doc_width + 1;
cy[i] = 1;
x[i] = r[i] * sn + cx[i];
y[i] = r[i] * cs + cy[i];
}
function updateRain() {
r[i] += s;
x[i] = r[i] * sn + cx[i];
y[i] = r[i] * cs + cy[i];
}
function raindropNS() {
for (i = 0; i < no; ++ i) {
updateRain();
if ((x[i] <= 1) || (x[i] >= (doc_width - 20)) || (y[i] >= (doc_height - 20))) {
makeRain();
doc_width = self.innerWidth;
doc_height = self.innerHeight;
}
document.layers["dot"+i].top = y[i];
document.layers["dot"+i].left = x[i];
}
setTimeout("raindropNS()", speed);
}
function raindropIE() {
for (i = 0; i < no; ++ i) {
updateRain();
if ((x[i] <= 1) || (x[i] >= (doc_width - 20)) || (y[i] >= (doc_height - 20))) {
makeRain();
doc_width = document.body.clientWidth;
doc_height = document.body.clientHeight;
}
document.all["dot"+i].style.pixelTop = y[i];
document.all["dot"+i].style.pixelLeft = x[i];
}
setTimeout("raindropIE()", speed);
}
if (ns4up) {
raindropNS();
}
else
if (ie4up) {
raindropIE();
}
// End -->
</script>
</body>
<font face="Tahoma"><a target="_blank" href="http://www.allaboutwebsite.com/"><span
style="font-size: 8pt; text-decoration: none">Allaboutwebsite Services</span></a></font>
17. Stars Moving
If you want to show stars moving in the background of your webpage then you can give this effect using the following code.<FONT face=Tahoma color=white>
<body>
<BODY BGCOLOR="#000000" onLoad="fly()">
<SCRIPT LANGUAGE="JavaScript">
SmallStars = 30;
LargeStars = 10;
SmallYpos = new Array();
SmallXpos = new Array();
LargeYpos = new Array();
LargeXpos = new Array();
Smallspeed= new Array();
Largespeed= new Array();
ns=(document.layers)?1:0;
if (ns) {
for (i = 0; i < SmallStars; i++) {
document.write("<LAYER NAME='sn"+i+"' LEFT=0 TOP=0 BGCOLOR='#FFFFF0'
CLIP='0,0,1,1'></LAYER>");
}
for (i = 0; i < LargeStars; i++) {
document.write("<LAYER NAME='ln"+i+"' LEFT=0 TOP=0 BGCOLOR='#FFFFFF'
CLIP='0,0,2,2'></LAYER>");
}
}
else {
document.write('<div style="position:absolute;top:0px;left:0px">');
document.write('<div style="position:relative">');
for (i = 0; i < SmallStars; i++) {
document.write('<div id="si"
style="position:absolute;top:0;left:0;width:1px;height:1px;background:#fffff0;fontsize:
1px"></div>');
}
document.write('</div>');
document.write('</div>');
document.write('<div style="position:absolute;top:0px;left:0px">');
document.write('<div style="position:relative">');
for (i = 0; i < LargeStars; i++) {
document.write('<div id="li"
style="position:absolute;top:0;left:0;width:2px;height:2px;background:#ffffff;fontsize:
2px"></div>');
}
document.write('</div>');
document.write('</div>');
}
WinHeight = (document.layers)?window.innerHeight:window.document.body.clientHeight;
WinWidth = (document.layers)?window.innerWidth:window.document.body.clientWidth;
for (i = 0; i < SmallStars; i++) {
SmallYpos[i] = Math.round(Math.random() * WinHeight);
SmallXpos[i] = Math.round(Math.random() * WinWidth);
Smallspeed[i]= Math.random() * 5 + 1;
}
for (i = 0; i < LargeStars; i++) {
LargeYpos[i] = Math.round(Math.random() * WinHeight);
LargeXpos[i] = Math.round(Math.random() * WinWidth);
Largespeed[i] = Math.random() * 10 + 5;
}
function fly() {
var WinHeight = (document.layers)?window.innerHeight:window.document.body.clientHeight;
var WinWidth = (document.layers)?window.innerWidth:window.document.body.clientWidth;
var hscrll = (document.layers)?window.pageYOffset:document.body.scrollTop;
var wscrll = (document.layers)?window.pageXOffset:document.body.scrollLeft;
for (i = 0; i < LargeStars; i++) {
LargeXpos[i] -= Largespeed[i];
if (LargeXpos[i] < -10) {
LargeXpos[i] = WinWidth;
LargeYpos[i] = Math.round(Math.random() * WinHeight);
Largespeed[i] = Math.random() * 10 + 5;
}
if (ns) {
document.layers['ln'+i].left = LargeXpos[i];
document.layers['ln'+i].top = LargeYpos[i] + hscrll;
}
else {
li[i].style.pixelLeft = LargeXpos[i];
li[i].style.pixelTop = LargeYpos[i] + hscrll;
}
}
for (i = 0; i < SmallStars; i++) {
SmallXpos[i] -= Smallspeed[i];
if (SmallXpos[i] < -10) {
SmallXpos[i] = WinWidth;
SmallYpos[i] = Math.round(Math.random()*WinHeight);
Smallspeed[i] = Math.random() * 5 + 1;
}
if (ns) {
document.layers['sn'+i].left = SmallXpos[i];
document.layers['sn'+i].top = SmallYpos[i]+hscrll;
}
else {
si[i].style.pixelLeft = SmallXpos[i];
si[i].style.pixelTop = SmallYpos[i]+hscrll;
}
}
setTimeout('fly()', 10);
}
// End -->
</script>
<!-- Script Size: 3.79 KB -->
</body>
</html>
18. Stars falling
In the previous code, you gave the effect of stars moving but in this code you can also give the effect of stars falling in your webpage. Read the code below.<script>
// Set the number of snowflakes (more than 30 - 40 not recommended)
var snowmax=35
// Set the colors for the snow. Add as many colors as you like
var snowcolor=new Array("#aaaacc","#ddddFF","#ccccDD")
// Set the fonts, that create the snowflakes. Add as many fonts as you like
var snowtype=new Array("Arial Black","Arial Narrow","Times","Comic Sans MS")
// Set the letter that creates your snowflake (recommended:*)
var snowletter="*"
// Set the speed of sinking (recommended values range from 0.3 to 2)
var sinkspeed=0.6
// Set the maximal-size of your snowflaxes
var snowmaxsize=22
// Set the minimal-size of your snowflaxes
var snowminsize=8
// Set the snowing-zone
// Set 1 for all-over-snowing, set 2 for left-side-snowing
// Set 3 for center-snowing, set 4 for right-side-snowing
var snowingzone=3
///////////////////////////////////////////////////////////////////////////
// CONFIGURATION ENDS HERE
///////////////////////////////////////////////////////////////////////////
// Do not edit below this line
var snow=new Array()
var marginbottom
var marginright
var timer
var i_snow=0
var x_mv=new Array();
var crds=new Array();
var lftrght=new Array();
var browserinfos=navigator.userAgent
var ie5=document.all&&document.getElementById&&!browserinfos.match(/Opera/)
var ns6=document.getElementById&&!document.all
var opera=browserinfos.match(/Opera/)
var browserok=ie5||ns6||opera
function randommaker(range) {
rand=Math.floor(range*Math.random())
return rand
}
function initsnow() {
if (ie5 || opera) {
marginbottom = document.body.clientHeight
marginright = document.body.clientWidth
}
else if (ns6) {
marginbottom = window.innerHeight
marginright = window.innerWidth
}
var snowsizerange=snowmaxsize-snowminsize
for (i=0;i<=snowmax;i++) {
crds[i] = 0;
lftrght[i] = Math.random()*15;
x_mv[i] = 0.03 + Math.random()/10;
snow[i]=document.getElementById("s"+i)
snow[i].style.fontFamily=snowtype[randommaker(snowtype.length)]
snow[i].size=randommaker(snowsizerange)+snowminsize
snow[i].style.fontSize=snow[i].size
snow[i].style.color=snowcolor[randommaker(snowcolor.length)]
snow[i].sink=sinkspeed*snow[i].size/5
if (snowingzone==1) {snow[i].posx=randommaker(marginright-snow[i].size)}
if (snowingzone==2) {snow[i].posx=randommaker(marginright/2-snow[i].size)}
if (snowingzone==3) {snow[i].posx=randommaker(marginright/2-
snow[i].size)+marginright/4}
if (snowingzone==4) {snow[i].posx=randommaker(marginright/2-
snow[i].size)+marginright/2}
snow[i].posy=randommaker(2*marginbottom-marginbottom-2*snow[i].size)
snow[i].style.left=snow[i].posx
snow[i].style.top=snow[i].posy
}
movesnow()
}
function movesnow() {
for (i=0;i<=snowmax;i++) {
crds[i] += x_mv[i];
snow[i].posy+=snow[i].sink
snow[i].style.left=snow[i].posx+lftrght[i]*Math.sin(crds[i]);
snow[i].style.top=snow[i].posy
if (snow[i].posy>=marginbottom-2*snow[i].size ||
parseInt(snow[i].style.left)>(marginright-3*lftrght[i])){
if (snowingzone==1) {snow[i].posx=randommaker(marginrightsnow[
i].size)}
if (snowingzone==2) {snow[i].posx=randommaker(marginright/2-
snow[i].size)}
if (snowingzone==3) {snow[i].posx=randommaker(marginright/2-
snow[i].size)+marginright/4}
if (snowingzone==4) {snow[i].posx=randommaker(marginright/2-
snow[i].size)+marginright/2}
snow[i].posy=0
}
}
var timer=setTimeout("movesnow()",50)
}
for (i=0;i<=snowmax;i++) {
document.write("<span id='s"+i+"' style='position:absolute;top:-
"+snowmaxsize+"'>"+snowletter+"</span>")
}
if (browserok) {
window.onload=initsnow
}
</script>
19. Always Changing Background Color
If you want the background of your page to change its color everytime then you can do this in Javascript. Read the code below.<html>
<head>
<script>
function initArray()
{
this.length = initArray.arguments.length
for (var i = 0; i < this.length; i++)
this[i+1] = initArray.arguments[i]
}
var hexChars = "0123456789ABCDEF";
function Dec2Hex (Dec)
{
var a = Dec % 16;
var b = (Dec - a)/16;
hex = "" + hexChars.charAt(b) + hexChars.charAt(a);
return hex;
}
function bgChanger (begin, end, steps)
{
steps = steps -1 ;
redA = begin.charAt(0) + begin.charAt(1);
red_valA = parseInt(redA,'16');
redB = end.charAt(0) + end.charAt(1);
red_valB = parseInt(redB,'16');
red_int = ((red_valB - red_valA) / steps) * -1;
grnA = begin.charAt(2) + begin.charAt(3);
grn_valA = parseInt(grnA,'16');
grnB = end.charAt(2) + end.charAt(3);
grn_valB = parseInt(grnB,'16');
grn_int = ((grn_valB - grn_valA) / steps) * -1;
bluA = begin.charAt(4) + begin.charAt(5);
blu_valA = parseInt(bluA,'16');
bluB = end.charAt(4) + end.charAt(5);
blu_valB = parseInt(bluB,'16');
blu_int = ((blu_valB - blu_valA) / steps) * -1;
step = 2;
red = red_valA;
grn = grn_valA;
blu = blu_valA;
document.bgColor = begin;
while ( steps >= step )
{
red -= red_int;
red_round = Math.round(red);
red_hex = Dec2Hex(red);
grn -= grn_int;
grn_round = Math.round(grn);
grn_hex = Dec2Hex(grn);
blu -= blu_int;
blu_round = Math.round(blu);
blu_hex = Dec2Hex(blu);
document.bgColor = red_hex + grn_hex + blu_hex;
step++;
}
document.bgColor = end;
}
</script>
</head>
<body bgcolor=#000000 text=#FFFFFF link="FF0000" vlink="8888FF" alink="FF00FF">
<script>
<!--
// black to black (pause)
i=1;
while(i<=10)
{
bgChanger("000000","000000",25);
// black to red
bgChanger("000000","FF0000",25);
// red to black
bgChanger("FF0000","000000",25);
// black to purple
bgChanger("000000","AA00EE",25);
// purple to black
bgChanger("AA00EE","000000",25);
// black to blue
bgChanger("000000","0000FF",25);
// blue to black
bgChanger("0000FF","000000",25);
// black to black (pause)
bgChanger("000000","000000",25);
i=i+1;
}
// -->
</script>
</head>
<body>
<BODY BGCOLOR=000000 text="#ffffff" link="#0000ff" vlink="#c00c0">
20. Falling Leaves
You can also give the effect of falling leaves in your webpage as you have given the effect of falling stars. Read the code below.<script language="JavaScript1.2">
//Pre-load your image below!
grphcs=new Array(6)
Image0=new Image();
Image0.src=grphcs[0]="leaves.gif";
Image1=new Image();
Image1.src=grphcs[1]="leaves.gif"
Image2=new Image();
Image2.src=grphcs[2]="leaves.gif"
Image3=new Image();
Image3.src=grphcs[3]="leaves.gif"
Image4=new Image();
Image4.src=grphcs[4]="leaves.gif"
Image5=new Image();
Image5.src=grphcs[5]="leaves.gif"
Amount=8; //Smoothness depends on image file size, the smaller the size the more you can use!
Ypos=new Array();
Xpos=new Array();
Speed=new Array();
Step=new Array();
Cstep=new Array();
ns=(document.layers)?1:0;
ns6=(document.getElementById&&!document.all)?1:0;
if (ns){
for (i = 0; i < Amount; i++){
var P=Math.floor(Math.random()*grphcs.length);
rndPic=grphcs[P];
document.write("<LAYER NAME='sn"+i+"' LEFT=0 TOP=0><img src="/+rndPic+"></LAYER>");
}
}
else{
document.write('<div style="position:absolute;top:0px;left:0px"><div
style="position:relative">');
for (i = 0; i < Amount; i++){
var P=Math.floor(Math.random()*grphcs.length);
rndPic=grphcs[P];
document.write('<img id="si'+i+'" src="'+rndPic+'" style="position:absolute;top:0px;left:0px">');
}
document.write('</div></div>');
}
WinHeight=(ns||ns6)?window.innerHeight:window.document.body.clientHeight;
WinWidth=(ns||ns6)?window.innerWidth-70:window.document.body.clientWidth;
for (i=0; i < Amount; i++){
Ypos[i] = Math.round(Math.random()*WinHeight);
Xpos[i] = Math.round(Math.random()*WinWidth);
Speed[i]= Math.random()*5+3;
Cstep[i]=0;
Step[i]=Math.random()*0.1+0.05;
}
function fall(){
var WinHeight=(ns||ns6)?window.innerHeight:window.document.body.clientHeight;
var WinWidth=(ns||ns6)?window.innerWidth-70:window.document.body.clientWidth;
var hscrll=(ns||ns6)?window.pageYOffset:document.body.scrollTop;
var wscrll=(ns||ns6)?window.pageXOffset:document.body.scrollLeft;
for (i=0; i < Amount; i++){
sy = Speed[i]*Math.sin(90*Math.PI/180);
sx = Speed[i]*Math.cos(Cstep[i]);
Ypos[i]+=sy;
Xpos[i]+=sx;
if (Ypos[i] > WinHeight){
Ypos[i]=-60;
Xpos[i]=Math.round(Math.random()*WinWidth);
Speed[i]=Math.random()*5+3;
}
if (ns){
document.layers['sn'+i].left=Xpos[i];
document.layers['sn'+i].top=Ypos[i]+hscrll;
}
else if (ns6){
document.getElementById("si"+i).style.left=Math.min(WinWidth,Xpos[i]);
document.getElementById("si"+i).style.top=Ypos[i]+hscrll;
}
else{
eval("document.all.si"+i).style.left=Xpos[i];
eval("document.all.si"+i).style.top=Ypos[i]+hscrll;
}
Cstep[i]+=Step[i];
}
setTimeout('fall()',20);
}
window.onload=fall
//-->
</script>

Get latest photoshop tutorials, design resources and articles directly in your email. Subscribe to Psdeluxe Feed and stay be informed about latest design news.



25 cool photoshop photo effects tutorials
100+ Old Coca cola posters
30 most important web and graphic design blogs
25 photoshop light effect tutorials
Create sexy cyborg
Light effect wallpaper in Photoshop
Creepy bloody text effect in Photoshop
Drawing realistic color portrait




























