Home » , , » Plugin Daftar Konten Otomatis Sederhana (1 Level)

Plugin Daftar Konten Otomatis Sederhana (1 Level)

Simple Auto Table of Content Plugin (1 Level)
(function($) {
$.fn.toc = function(o, p) {
p = $.extend({title: "Table of Content"}, p);
this.prepend('<div id="toc-list"><strong>' + p.title + '</strong><ol></ol></div>').children(o).each(function(i) {
i = i + 1;
$(this).attr('id', 'section-' + i).nextUntil(o).after('<a href="#toc-list">Top &uArr;</a>');
$('<li><a href="#section-' + i + '">' + $(this).text() + '</a></li>').appendTo('#toc-list ol');
});
};
})(jQuery);

Penggunaan

$('#parent').toc('h3', {title: "Tabel Konten:"});

Demo

Menambahkan Efek Animasi

Kode ini berada di luar plugin, dan memiliki cara kerja yang tidak jauh berbeda dengan animasi tombol back to top:

$('#toc-list a, a[href="#toc-list"]').on("click", function() {
var hash = this.hash;
$('html, body').animate({scrollTop:$(hash).offset().top}, 600, function() {
window.location.hash = hash;
});
return false;
});
Jika Anda menyukai Artikel di blog ini, Silahkan klik disini untuk berlangganan gratis via email, dengan begitu Anda akan mendapat kiriman artikel setiap ada artikel yang terbit di Creating Website

0 comments:

Post a Comment

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Homtimpa - All Rights Reserved
Template Modify by Creating Website
Proudly powered by Blogger