Apa kabar sobat blogger-ku semua, apa kabar kalian? semoga baik-baik saja amin :) kali ini saya akan memposting tutorial membuat tombol Back To Top pada blog, Memudahkan user atau pengunjung kembali ke bagian atas blog hanya sekali klik, tanpa harus men-scroll mousenya atau "mengusap-usap" jarinya di "touch pad" atau layar SmartPhone-nya wkwk.
Saya rasa banyak yg ingin memasang tombol "kembali ke atas" ini karena kadang/sering harus membuka postingan dengan komentar yang banyak, sehingga "Kebawah Banget" dan harus bersusah-payah "scroll" ke bagian atas.
Nah, dengan adanya tombol "Back to Top" ini, tinggal "klik" dan tampilan bagian atas blog akan tersaji secara otomatis, keren kan? tentu keren dong hehe, langsung simak baik-baik ya sobat
Ikuti Langkah-langkahnya / Cara Memasangnya.
1. Pastikan di Template blog sobat sudah ada kode jQuery, yaitu kode seperti dibawah ini:
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js' type='text/javascript'/>
Atau seperti ini:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
- Pilih Template > Edit HTML
- Ketik (CTRL+F) untuk mempermudah mencari kode </head> di HTML
- Copy salah satu kode di atas lalu Paste di atas kode </head> tadi.
- Save!
2. Klik "Layout" atau (Tata Letak)
3. Klik "Add Gadget" di Sidebar
4. Pilih "Javascript/HTML"
5. Copy dan Paste kode berikut dibawah ini:
<style>
.mbw-back-to-top {
position: fixed;
bottom: 2em;
right: 10px;
text-decoration: none;
padding: 1em;
display: none;
cursor:pointer;
}
</style>
<img class="mbw-back-to-top" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhluPagB4eICzGrxWUtKXcgNIO7vyopbkHboNskcXOzSGhu3W7holtPKSrPmaXISgxFb6zA29Tf0ym9BMfd7llDv0l_LPCxTPmVpI8Mst7q0kcFlVwT3xtZo6gyj270ol98FgGVVkKWTeE/s1600/back+to+top.png" />
<script type="text/javascript">
/*****mybloggersworld.com***/
jQuery(document).ready(function() {
var offset = 220;
var duration = 500;
jQuery(window).scroll(function() {
if (jQuery(this).scrollTop() > offset) {
jQuery('.mbw-back-to-top').fadeIn(duration);
} else { //www.mybloggersworld.com
jQuery('.mbw-back-to-top').fadeOut(duration);
}
});
jQuery('.mbw-back-to-top').click(function(event) {
event.preventDefault();
jQuery('html, body').animate({scrollTop: 0}, duration);
return false;
})
});
</script>
.mbw-back-to-top {
position: fixed;
bottom: 2em;
right: 10px;
text-decoration: none;
padding: 1em;
display: none;
cursor:pointer;
}
</style>
<img class="mbw-back-to-top" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhluPagB4eICzGrxWUtKXcgNIO7vyopbkHboNskcXOzSGhu3W7holtPKSrPmaXISgxFb6zA29Tf0ym9BMfd7llDv0l_LPCxTPmVpI8Mst7q0kcFlVwT3xtZo6gyj270ol98FgGVVkKWTeE/s1600/back+to+top.png" />
<script type="text/javascript">
/*****mybloggersworld.com***/
jQuery(document).ready(function() {
var offset = 220;
var duration = 500;
jQuery(window).scroll(function() {
if (jQuery(this).scrollTop() > offset) {
jQuery('.mbw-back-to-top').fadeIn(duration);
} else { //www.mybloggersworld.com
jQuery('.mbw-back-to-top').fadeOut(duration);
}
});
jQuery('.mbw-back-to-top').click(function(event) {
event.preventDefault();
jQuery('html, body').animate({scrollTop: 0}, duration);
return false;
})
});
</script>
Kode yang berwarna merah adalah image "Back to Top". Sobat bisa menggantinya dengan gambar lain sesuai dengan selera Sobat, juga sesuai dengan background blog Sobat.
Pilihlah salah satu Url Gambar yg sobat inginkan di Bawah ini!
Pilihlah salah satu Url Gambar yg sobat inginkan di Bawah ini!
Ini pilihan gambar/tombol "Back to Top" dan URL-nya yang bisa Anda gunakan. Copas link URL-nya ke bagian yang berwarna merah dalam kode di atas tadi.
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgC_ZmKdwRkJ8varu7ZAhuBx3yJB6D9wbmDRtJMU1X3bqefcOxwHO5EBfnXmEsxPGLD3EUoBRazNuI5nphY1K5qj2QTTuczymePggBM_L3RgPZqTllcr4ySh2c8FHawqLLe0QOIOY0v4rQ/s1600/back+to+top.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihP6aevPFM7ULID0_22htmjrbzv2UtvW562ejd9mHrj7LukN3_O9sVgZBJrcGWENicRlFbcVj91YFSOUt06LuM4sk7ZfwxyRF4gJd096SDzoSc1Z_nyaLvePJEjEKuwU2enkXOqNPhI3o/s1600/back+to+top.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg17taajlHM2L_3Ic2DX620cH_DHi-oOg8V4_YkHTjxxAqZ7LkwDtJojLzDi77zzF1b3OFjdhDhhcIG3eO9YsOyiayw-HtxpibjENs9bdYIFopU1oEAlV8BKZwygXWJb5rAI-V04tUL0Pc/s1600/back+to+top.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgC_ZmKdwRkJ8varu7ZAhuBx3yJB6D9wbmDRtJMU1X3bqefcOxwHO5EBfnXmEsxPGLD3EUoBRazNuI5nphY1K5qj2QTTuczymePggBM_L3RgPZqTllcr4ySh2c8FHawqLLe0QOIOY0v4rQ/s1600/back+to+top.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlB1CUlTQ1a8BOqmxkkY4hvE-tSCUiOsKJ8q6C8lANiYhdiJsUrSyva8UebFtZICMkpCpt76A5di4WJlECrxY0wdXDN5iv0JB14E8zUBscySb8KPwTuR4HX6IqjgtBUpREcbeoXiEzFuE/s1600/back+to+top.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNB6AjuL6hd7rxxbUHCJ8xqWTzBhpY69gzdv91PTL8X9jRXkygTXG6b_l6R6eNhN6IK6QoA8Y20VgiWKCmfX6bSabzmjQr_BrIkNz7UPfpL6hnRhF7hwTm-bW1ojIesnQ1w-vQ_2LPCAU/s1600/back+to+top+button.gif
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZ3bnVbCdY_3BTbLkW-kUXDkAjDe-x91vwyzfcjmhhhiHTCv1uJrCNUs4rApq3Db-yetH6-7lVM-KJrjlh3sOay878zAf7Re71Zs1qiDdFROL1pPVuXNl0hh8iGoIyv1cU4dUCTyCE7Sw/s1600/back+to+top+button.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgn3mA-mqFtxtpofUVHXdkiPEvNlG3DNTdjqEFfibHN60gfodgaNKbGSRDFy7s3gY9SpUnEZ-kpec-5-eC-6vM4YUBm6SgfZ1WLkm2fU38J35xGBA5iRaaEot6Krst3Af7v_W9Jx2sUqXQ/s1600/back+to+top+button.gif
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoIJlexhbMXG9J0n9UewmDdE3n1Pv-mRdd2vgRG1pHmyF2V0nLSJehlysS4dDwuDHGMR2Ueih8z6Kytv3l1xsgpyqIvho3VZ4H11vAFwGAISTFJ-tgX2f26DDnk-Qyjxf1HzBKepiBF-k/s1600/back+to+top+button.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhluPagB4eICzGrxWUtKXcgNIO7vyopbkHboNskcXOzSGhu3W7holtPKSrPmaXISgxFb6zA29Tf0ym9BMfd7llDv0l_LPCxTPmVpI8Mst7q0kcFlVwT3xtZo6gyj270ol98FgGVVkKWTeE/s1600/back+to+top.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifoEnwZO8PKDbasuSFPfSJe66hrLrNtZzxaTLZ-9iqGlMDuh8Ns0IkC1N2H1XRbukGgWNNcrRmBYuf_rdy3_v0TrWQVmnQkbEGeKcf1Vxk8lVWOTvTNnJr8_EI-BfG3-gmFXul16qTWNM/s1600/Back-To-Top.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4UiSEwDkYGn9cvLHbpDj7YPHpLgGXpXfno43dIzSoKIRr41YkS1u92DLkMQR1e6mN8uVadKgrwURBZAZtvoQJEMQfY_viswNQlslEoX2oHrM3sxamdJjrDat8admWVswF7hthgLN6Ctw/s1600/Back-To-Top.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfRa-SH82N8qJWu7HGZ_-6JFQQcWmWuFAoJ5wrEykQMpNa8gvzsiwKIFXlzMkMYIzTS1-tjreJxJAozrlOnwijyWW6QbmkdIUpTeuyWrg1dghrbmpM1UTSH8xmEUwVecMQ7VavHdwbYjk/s1600/back-to-top-button.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6dorbDuqx6MhSNASKWElL8xvx9zK9N22bJlfmgXqyncffq9SRmtX49isEkuFRVFWFo0fplG802p63uBVxnmo8rS1Eys_8TDkUPjst6Yiyfdv69zIzzYaOzzd48hwxRDssq3vFyMTHvBI/s1600/back-to-top-button.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQxo4CHOZD6jzWYHRzTA_AXQGsAS8B8Fv7VPAUKa_V8HppcOenfLiORkJJAvJZ7C-pLXvETq-q-Py1IWJ0N3GwLA7WXVM5TejqhWEnwymSKT3jfGp6LOMISWdg97Y6T6jW1_iHTHrmCKQ/s1600/back-to-top-button.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8nKaYeQIIXYpGnuq-59gip3kNTyI7hU6Uy12Zb3geDjLe4Pa6qcVuSUIKPE4exVNctySMi5OCg3CI0s5hGhbBFb_0uoD6Xr1P0-mBEHRZgaoJMldixPRnP_FOnQ5nv7rCVw2GF5byLAs/s1600/back_to_top_button.png
1. Layout atau disebut (Tata Letak)
2. Add Gadget
3. Pilih HLML/Javascript
4. Copy kode dibawah ini kemudian Save
<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>
<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>
0 Comments
Posting Komentar
Ayo berkomentar sesuai dengan topik pembahasan.