Featured Post

[Feature] Tradisi Pengantin Tebu

Cara Membuat Back to Top di Blogger

Saat kita baca postingan yang panjang banget sampe ke bawah, terus pengen baca lagi dari atas tapi scroll mouse rusak. Apa pernah loe ngalamin hal tersebut gan? Kalo pernah pasti repot karena harus narikin tombol scroll di browser ya gak. Apalagi kalo pake laptop cuma pake touch pad waduh bikin sebel.

Nah kita sebagai pemilik blog harus cari cara buat mengatasi masalah itu, biar pengunjung blog betah baca postingan kita gan. Caranya ya kita pasang tombol back to top, jadi pengunjung tinggal ngeklik tombol aja kalau pengen balik ke atas gan.

Blog kalian udah ada tombol back to topnya belom? Kalo belom, pasang sekarang juga, tombol back to top ini emang bukan navigasi utama tapi bisa jadi sangat penting buat beberapa pengunjung gan. Gak susah kok membuat tombol back to top di blog gan cuma tinggal nambahin widget tanpa perlu edit HTML.

Kali ini gw bakal share cara membuat tombol back to top di blog yang gampang gan. Kalo loe berminat silahkan langsung disimak cara buatnya gan gak pake ribet. Contohnya kayak yang ada di blog ini posisi tombol ada di kanan gan.




Cara Membuat Tombol Back To Top Keren Di Blog



  • Pertama masuk ke Blogger lalu pilih Layout terus Add a Gadget dan tambahin HTML/JavaScript gan. Terus tinggal loe pastein kode di bawah ini di kotak kosongnya.
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

<script type="text/javascript" >


var scrolltotop={
    //startline: Integer. Number of pixels from top of doc scrollbar is scrolled before showing control
    //scrollto: Keyword (Integer, or "Scroll_to_Element_ID"). How far to scroll document up when control is clicked on (0=top).
    setting: {startline:100, scrollto: 0, scrollduration:1000, fadeduration:[500, 100]},
    controlHTML: '<img src="URL Gambar Back To Top" />', //HTML for control, which is auto wrapped in DIV w/ ID="topcontrol"
    controlattrs: {offsetx:5, offsety:5}, //offset of control relative to right/ bottom of window corner
    anchorkeyword: '#top', //Enter href value of HTML anchors on the page that should also act as "Scroll Up" links

    state: {isvisible:false, shouldvisible:false},

    scrollup:function(){
        if (!this.cssfixedsupport) //if control is positioned using JavaScript
            this.$control.css({opacity:0}) //hide control immediately after clicking it
        var dest=isNaN(this.setting.scrollto)? this.setting.scrollto : parseInt(this.setting.scrollto)
        if (typeof dest=="string" && jQuery('#'+dest).length==1) //check element set by string exists
            dest=jQuery('#'+dest).offset().top
        else
            dest=0
        this.$body.animate({scrollTop: dest}, this.setting.scrollduration);
    },

    keepfixed:function(){
        var $window=jQuery(window)
        var controlx=$window.scrollLeft() + $window.width() - this.$control.width() - this.controlattrs.offsetx
        var controly=$window.scrollTop() + $window.height() - this.$control.height() - this.controlattrs.offsety
        this.$control.css({left:controlx+'px', top:controly+'px'})
    },

    togglecontrol:function(){
        var scrolltop=jQuery(window).scrollTop()
        if (!this.cssfixedsupport)
            this.keepfixed()
        this.state.shouldvisible=(scrolltop>=this.setting.startline)? true : false
        if (this.state.shouldvisible && !this.state.isvisible){
            this.$control.stop().animate({opacity:1}, this.setting.fadeduration[0])
            this.state.isvisible=true
        }
        else if (this.state.shouldvisible==false && this.state.isvisible){
            this.$control.stop().animate({opacity:0}, this.setting.fadeduration[1])
            this.state.isvisible=false
        }
    },
  
    init:function(){
        jQuery(document).ready(function($){
            var mainobj=scrolltotop
            var iebrws=document.all
            mainobj.cssfixedsupport=!iebrws || iebrws && document.compatMode=="CSS1Compat" && window.XMLHttpRequest //not IE or IE7+ browsers in standards mode
            mainobj.$body=(window.opera)? (document.compatMode=="CSS1Compat"? $('html') : $('body')) : $('html,body')
            mainobj.$control=$('<div id="topcontrol">'+mainobj.controlHTML+'</div>')
                .css({position:mainobj.cssfixedsupport? 'fixed' : 'absolute', bottom:mainobj.controlattrs.offsety, right:mainobj.controlattrs.offsetx, opacity:0, cursor:'pointer'})
                .attr({title:'Scroll Back to Top'})
                .click(function(){mainobj.scrollup(); return false})
                .appendTo('body')
            if (document.all && !window.XMLHttpRequest && mainobj.$control.text()!='') //loose check for IE6 and below, plus whether control contains any text
                mainobj.$control.css({width:mainobj.$control.width()}) //IE6- seems to require an explicit width on a DIV containing text
            mainobj.togglecontrol()
            $('a[href="' + mainobj.anchorkeyword +'"]').click(function(){
                mainobj.scrollup()
                return false
            })
            $(window).bind('scroll resize', function(e){
                mainobj.togglecontrol()
            })
        })
    }
}

scrolltotop.init()

</script>

  • Kalo udah di pastein sekarang tinggal di ganti URL Gambar Back To Top sama url gambar punya loe gan lalu di Save. Coba sekarang buka blog loe pasti udah ada tombol back to topnya gan.

Kalo loe gak punya gambar tombolnya ni gw sediain gan, ada yang animasi sama standar tinggal dipilih aja.


Kode HTML'nya yang Animasi :

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnNUCmZPHvWuoJ6Q7gytrTO7slp1vq0dNzlIztwpip9nd6PdSPmHLJxj2fSMtXF9hsKDW2b98GhDUAaryznnH_nlNVkppGL6r5CRb35Wz847vbQM8nIxdn-Sp-d3nuQPT6ze3lYFX5QHb7/s1600/back+to+top10.gif

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgj_L6KtVj6veU_faeZNjXMu6lgt3_qVf1cEb6ocWexC0fV0Bf_0jcl8vk8-YBhZF-LfA4I837XB1YQUce4Nxl1LWybFym4rhhuSRPLJXZaR0BR3hnXDBwZRqQkO5-VF-mRNcKRD1JFY-vA/s1600/back+to+top9.gif

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8S0RFyafVfgO8Lh7H7yDzR-poOGfXai6vEcsj29IJi0WnNz5FB5znL8yA4fVNkGSKq1KKAbUed-pzImYIt9M9a0JioHw04r87GyyzUJaA3XiIxHOfStGms-GVEEedvePYDRg4SAm1tCEi/s1600/back+to+top4.gif

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-2VTDVrWK29wvhDVCt4VShCTCq1hZRlwQeldi47hGWjJu6JUzW36fCwhgYyHycUwVhWuSiKlSGtGe9kab1sZHuteKJJqc5o-PZlBEU_IlPONvDR3wGNONjP7k7-9hI42nYuXI9l9nLPW6/s1600/back+to+top7.gif

 Kode HTML'nya yg standar:
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1H64OudTxhQkKaq191iwdE45q86TwEV06jxFa7M-9M9XWQBozptx8DpCwSKs5g0pjfnYWD10NjU7ixY-kLvtY3Ui7l1fCfyk_RBQvY0mOaulzvCMoFf5x91bT4lT9yRx7-cmjyO8rJ2P8/s1600/back+to+top15.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhI3DCJj2HJN0vsSCJww0aN6qdyF7yhHDPDJgunaCcoL2TpVSdQc-PmhH-ncP-JrAgBCJ0qoep8VwlkSlOE7gumjcUaaBnT6vAKoid8MWu6Xy2vQpsVYzVKgE6GPVNO0MfBrikbV9IExJaf/s1600/back+to+top14.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-l3UZ21rSfbChujvZMKRHVuCS5qjFGPXDGb99y2XHk1_8SQmhWSO7eUV6rCiqvSYwyU48Vbqaug_PQzDF4lrUPxag07WFHs9NWRUxOce5FjnXBvXpxk3kWUB5MHjvZ0B2ghTopXMjI8PI/s1600/back+to+top13.png

Beres gan, gampang kan cara membuat tombol back to top di blognya. Ow ya kalo loe mau rubah kecepatan scrollnya bisa di edit aja scrollduration, semakin besar angkanya semakin lambat gerakan ke atasnya gan.


Sekian dulu yang bisa gw share tentang cara membuat tombol back to top, semoga bermanfaat buat kalian semua. Jangan lupa ninggalin komentar ya gan

^^ Arigatou Gozaimassu ^^

Komentar