Jumat, 05 Oktober 2012

You are here : Home » Ketagihan Javascript » Membuat Animated Title Keren

Membuat Animated Title Keren

animated title

Seperti apa itu animated title ??

Coba Agan buka link ini, lihat title bar nya pada saat sedang loading. Sederatan angka-angka berubah menjadi judul postingan yang di tuju. Bagaimana keren bukan ??

Sekarang coba Agan reload atau refresh halaman yang sedang Agan baca ini. Pada halaman ini tidak tertanam animated title.

Apabila Agan ingin semua halaman di beri animated title, Agan masukkan kode yang nanti saya beri di salah satu elemen pada Tata Letak.

Sementara apabila hanya ingin di halaman tertentu saja, maka masukkan di dalam postingan yang di kehendaki. Tepatnya di tool "HTML" (Jangan di Compose) letakkan di atas isi postingan.

Untuk kodenya sendiri, ini dia magic javascript.

<script language="JavaScript1.2">

/*
Visit http://ketagihanbaca.blogspot.com/
*/

if (document.all||document.getElementById){
var thetitle=document.title
document.title=''
}

////Animation code below
////based on script from http://wsabstract.com/script/script2/statusanimate.shtml

var data="0123456789";

var done=1;
function statusIn(text){
 decrypt(text,2,1);
}

function statusOut(){
self.status='';
done=1;
}

//-------------------------\\
//decrypt(string, int, int)\\
//-------------------------\\
//
//text(string): the text to be decrypted on
//the status bar.
//
//max(int): the number of times a random string
//is displayed before the next character is
//'decrypted'.
//
//delay(int): the number of milliseconds between
//each display of a random string
//
//Example:
//decrypt('Enter my site.',10,10);
//
//text = 'Enter my site.' :: 'Enter my site.' is
//eventually decrypted
//
//max = 10 :: a different random string is dis-
//played 10 times before a new character is
//decrypted

function decrypt(text, max, delay){
 if (done){
  done = 0;
  decrypt_helper(text, max, delay,  0, max);
  }

}

function decrypt_helper(text, runs_left, delay, charvar, max){
 if (!done){
 runs_left = runs_left - 1;
 var status = text.substring(0,charvar);
 for(var current_char = charvar; current_char < text.length; current_char++){
  status += data.charAt(Math.round(Math.random()*data.length));
  }
 document.title = status;
 var rerun = "decrypt_helper('" + text + "'," + runs_left + "," + delay + "," + charvar + "," + max + ");"
 var new_char = charvar + 1;
 var next_char = "decrypt_helper('" + text + "'," + max + "," + delay + "," + new_char + "," + max + ");"
 if(runs_left > 0){
  setTimeout(rerun, delay);
  }
 else{
  if (charvar < text.length){
   setTimeout(next_char, Math.round(delay*(charvar+3)/(charvar+1)));
   }
  else
   {
   done = 1;
   }
  }
 }
}

//if IE 4+ or NS 6+
if (document.all||document.getElementById)
statusIn(thetitle)
</script>


Selamat mencoba.

1 komentar:

  1. Again, we are looking for something a bit more to provide a vocabulary through swatches, color books and computer files to enable developed-world companies to talk to their overseas suppliers.
    There is no shame in asking for a problem when you find something that you know,
    a bona fide laptop operating system is a bit costlier than the others.
    Stretched lobe earrings : Women from the north
    Kenyan Masai tribe may think you're hot but only if you're
    a petite woman.

    my web-site - Ao so mi nu

    BalasHapus