Tombol "Back to Top" memudahkan user atau pengunjung kembali ke bagian atas blog, dalam satu klik, tanpa harus men-scroll mousenya atau "mengusap-usap" jarinya di "touch pad" atau layar SmartPhone-nya.
Saya sendiri merasa butuh memasang tombol "kembali ke atas" ini karena kadang/sering harus membuka postingan dengan komentar yang banyak, sehingga "turun banget" dan harus bersusah-payah "scroll" ke bagian atas.
Nah, dengan adanya tombol "Back to Top" ini, saya tinggal "klik" dan tampilan bagian atas blog akan tersaji secara otomatis.
Cara Memasang Back to Top
1. Pastikan di template blog Anda sudah ada kode jquery, yaitu kode seperti 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>
Kalau belum ada, lakukan langkah ini:
- Template > Edit HTML
- Cari (CTRL+F) kode </head>
- COPY salah satu kode tersebut dan PASTE di ataskode </head> tadi.
- Save!
2. Klik "Layout" (Tata Letak)
3. Klik "Add Gadget" di Sidebar
4. Pilih "Javascript/HTML"
5. Copy dan Paste kode berikut 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/AVvXsEhMfxTmeqhForrauAT4MvvnyWStx8TPvUgp1IRDoxf2MGWFAuT0Olsr-URsJbW_2ACTXcj-jem3lF97NvGGopiPvOjFINwFgCa0TS8glkPx2iQ7blXmCPLHh4CWyYmD8NJhkDfYJKZsT7w/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/AVvXsEhMfxTmeqhForrauAT4MvvnyWStx8TPvUgp1IRDoxf2MGWFAuT0Olsr-URsJbW_2ACTXcj-jem3lF97NvGGopiPvOjFINwFgCa0TS8glkPx2iQ7blXmCPLHh4CWyYmD8NJhkDfYJKZsT7w/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". Anda bisa menggantinya dengan gambar lain sesuai dengan selera Anda, juga sesuai dengan background blog Anda.
Koleksi Gambar Tombol Back to Top untuk Blog
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/AVvXsEj_F338Q4fEJGducoGVcFgqXXdPVipG-TsFIk2Z6qPrYVZay5EnW8gbwqJsZCTRXzPr-whWPM21jlq8xxUjy2BHAvv4YCNhcI5z28NjnXkR-g8N_t98nzLz35I1qcIc2mr-rsii3da5wtI/s1600/back+to+top.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOA0wRS_wZuKSyvH6RQBNR4RmeXE40Qn9dXcdGSaCuDGhigGIHmnFLlgwVnjETBERR4ZabwX4ICWE3UVTyNqk3ofczCg3yz8VrAhV__3uErd2LvS7U3bCde76C1po3sFvxNTIWfyClvvQ/s1600/back+to+top.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaVcAzgOhhkULKp06-oQ2ASryhDdvHcf0ZPx9LcnylRi53CqKa7fRoyTIfoV9E2zRi0dow5uKBSdOjiuf-xmHpaNAgHwY9OnJpafsQ_7VCr4WgMLN5gEjScAKb_EOm6HTh9SgYM6IyQUw/s1600/back+to+top.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZm9ppN5ajK3n6DGc6TY-4hHJj3cmeWTkUVAOcbK0yAPsvCGlc1Ks7TCCmKilbz_y9nPl3bRsMjWufjS4dxLX6VLdhRu8R1O0uxUe5NR16rBe3tGZcbR4lP6BYCjDdGvTxS_lmpunSS2M/s1600/back+to+top.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfFRJUAssIp3NoJjasDHWtHpvSBLpKX2cC_InnuMD7UwfHe0yF3mrXhiUJGTCZ7qERFS8xjLLO1Ed2dKRn5uSH1A9WWqXgNhiXggDF0ZWLBururaHcqWdX5STugKNELL1tW54L4VF1WAc/s1600/back+to+top+button.gif
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjB5uumr12q53yR4R3a9uy3Kul-yC_7H5lmLwWqsQZA3WV7a-2ZMt0D47SQbaypQ2rF5hNiqwOkhcaLwuBhxncNjFjIoJU8PRzo0SBuS6IGJZJbbOftjQPnIz5nuM9jLu1_9fylI6pTgA/s1600/back+to+top+button.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcTZe1WnbobgTh4kRR1fPc2VnRFKgZvrgxGpWDiE81gRd2tSHOTt-r57aFPmIXhnXUHlLOF7zvFFx8H2sWfa2hcu66h91p7pAfDLgzTL_R8dFtNRsqjU8j59L8tgzF2k1dBJdgrnfBEwQ/s1600/back+to+top+button.gif
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjaZQFmKCkHl3kreIrPdMrh-t-sqGWqnA6Gq9kZsupHinX0rIxe9iVgi1N0SlSU7opVXoyOwvi8Y8vV5XASUSQwjQCnw78Vj59X6fpXLnSOg-Pff-8qd-L-PPc9Bsf2lZ_YlbdEnPy9KSY/s1600/back+to+top+button.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMfxTmeqhForrauAT4MvvnyWStx8TPvUgp1IRDoxf2MGWFAuT0Olsr-URsJbW_2ACTXcj-jem3lF97NvGGopiPvOjFINwFgCa0TS8glkPx2iQ7blXmCPLHh4CWyYmD8NJhkDfYJKZsT7w/s1600/back+to+top.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiP32URYRBFhPHJz_twC_8YmIExc8MOTAZqJE3I8H0f3Q3gmlcoR5FmQ5Z-DARg1axZhQ0slHX__khpypEuk8ELCgq01qRJlVQ40uJg7tQr5GcE8Z0XOSuf9KhCXCjrqstmQ7PgfuGtFtc/s1600/Back-To-Top.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqyQ286KdmBqAd4DNYtN8jC1pUAI99J-QpeJd1hEcCsQMsoPf0yFFFemE1nF126bfemasqvUWw80i5IbSifmDCCUmhhd5Jf1TEElTWHkz4YHdho1iW52qoD3BcJXaGm3qAd6WtTMIPy9E/s1600/back-to-top-button.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEin23M06qsfzJJV4ehScLtSrjjQ7sBrNcZ1hUIDesig3YEmJ9WkQxK9bHzXQA6wutD8OJXXgGz7qph47DokX_p-j8fNmG8RbkR4-C89ifyi7bMBDQdiGX6Q05XSu-8r4l10LUuc5MPKdqs/s1600/back-to-top-button.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLTUYBRHtlLwBkgB0QJu1iTbyGX1-U7GgsTgVGOz6rEy3HJk6AUcjfCfPi0UeU12Kwmav7CvoCsaIRTbCJ918ewoxBpuxZcFE42VbrsLykSAmbBQV-3aYFQO-JYO3cyWSdbaRmXIewbVs/s1600/back-to-top-button.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilSXv5Xl9s1oIRONQsXHo49OtVtBtP8Z1VFWiSbc44_xA5mETZxQVTCGsUI-gfwZRhoN5aJ9HSnYxkjJP7r4vtG77rslTwwAnE3PR_uERu2fi5IBn42ul9VTNUwEybzFOoPJ-SXjHk82g/s1600/Back-To-Top.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXDMv8ExdmvfFYhM4ZqQmw2H9vfJMM4fA0-ClFYCLgjtzslJD3_sueiyrbzx0k2TSPFk4MxmuEfj6EDEYTRThyphenhyphenyAKrA5HQRUL00-Ysh7CVuxjFZPBVpx8nPfgC00EAH4I4fkNI5m0oUmw/s1600/back_to_top_button.png
Alternatif Cara Memasang Back to Top
Jika cara di atas tidak berhasil, coba lakukan langkah berikut ini.1. Layout
2. Add Gadget
3. HLML/Javascript
4. COPAS kode berikut ini dan 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>
Itu dia cara membuat atau memasang tombol Back to Top di blog blogspot untuk kenyamanan dan kemudahan pengunjung, juga kemudahan kita sendiri sebagai admin blognya. Good Luck and Happy Blogging!
0 Response to "Cara Memasang Back to Top pada Blog"
Post a Comment