Fancybox (http://fancybox.net) is another lightbox-like plugin for jquery. In my opinion, this plugin is much sweeter than any other plugins, it has a fancy look (just like his name) and very easy to use.
But i'm not going to write a review about this plugin in this post. What i'm going to write is about how to make the box auto closed in some interval. It's like what you see in facebook dialog, when you have done something like adding new friend, it will display a dialog box saying "Friend requested pending, waiting for Abe Tobing approval", then the dialog automatically closed within some interval.
Before you read this further, i assummed that you have an experience using this plugin before or you have a basic knowledge of jquery.
OK, cut the crap, and let's get to the core.
In the plugin's documentation (http://fancybox.net/howto) there's an option called callbackOnShow. We could use this option to trigger the auto close event. All you have to do is set the options like this:
$('a.fancydialog').fancybox({
callbackOnShow: function () {
setTimeout ('$.fn.fancybox.close ()', 2000);
}
});
The line: setTimeout ('$.fn.fancybox.close ()', 2000); means that it will auto close in 2000 miliseconds (2 seconds). You could set this with higher value so the box will show in a longer time.
I use this code in some cases in my client websites, i hope this is useful to any of you who want the auto close function in your fancybox
Comments
Hello,
aku hoirul, catatan yang bagus, aku juga menggunakan fancybox, tapi aku punya keluhan tentang iframe. apakah anda bisa membantuku?
iframe yang diberikan oleh fancybox tidak bisa menutup kembali secara klik. maksudnya adalah ketika iframe URL kita tampilkan , yang didalamnya ada beberapa tombol yang seharusnya ketika di klik maka akan kembali menutup popup dan melanjutkan proses klik didalam page nya.
yang sudah diberikan iframe dalam fancybox adalah ketika di klik maka proses berjalan didalam popup, yang kuinginkan adalah sebaliknya popup tertutup lalu proses berjalan di page aslinya bukan yang popup.
mohon saran dan infonya ya
terima kasih sebelumnya
salam
hoirul
coba gunakan:
parent.$.fancybox.close();
Add new comment