Demo:
Link 1
Link 2
Link 3
The Oldschool
Efek hover menggunakan CSS. Efek sederhana ini yang paling sering digunakan. Ketika mouse masuk dan mouse keluar dari link, warna akan berubah.1 2 3 4 | <style type="text/css"> #oldschool a{color:#999} #oldschool a:hover{color:red}</style> |
Tanpa CSS, warna-warna tersebut langsung dimasukkan dalam script menggunakan method
.css()1 2 3 4 5 6 7 | <script type="text/javascript">$(function(){ $('#oldschool a').hover( function(){$(this).css('color','red')}, function(){$(this).css('color','#999')});};</script> |
.addClass() dan .removeClass().1 2 3 4 5 6 7 8 9 10 11 | <style type="text/css">#oldschool a, .moout {color:#999}.moin {color:red}</style><script type="text/javascript">$(function(){ $('#oldschool a').hover( function(){$(this).addClass('moin').removeClass('moout')}, function(){$(this).addClass('moout').removeClass('moin')})};</script> |
Link 1
Link 2
Link 3
The Effect
Efek ini menggunakan plugin jQuery Color jadi pastikan plugin itu juga dimuat di halaman ybs. Jika menggunakan wordpress, cukup menambahkan baris<?php wp_enqueue_script('jquery-color');?> pada file template kita.Tanpa CSS, yaitu dengan memasukkan warnanya langsung ke dalam script.
1 2 3 4 5 6 | <script type="text/javascript">$(function(){ $('#contoh a').hover( function(){$(this).stop().css({'color':'red'})}, function(){$(this).stop().animate({'color':'#999'},500)}) });</script> |
Karena efek
.animate() pada jquery tak dapat mengambil nilai dari CSS secara langsung, maka kita buat dummy tag untuk mengambil warna dari CSS.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <style type="text/css"> #dummyin, .moin {color:red} #dummyout, .moout, #contoh a {color:#999}</style><script type="text/javascript">$(function(){ var moin=$('#dummyin').css('color'); var moout=$('#dummyout').css('color'); $('#contoh a').hover( function(){$(this).stop().css({'color':moin})}, function(){$(this).stop().animate({'color':moout},500)});});</script><div id="dummyin" class="in"></div><div id="dummyout" class="out"></div> |
Jadi lebih cantik bukan?!
Tidak ada komentar:
Posting Komentar