Monday, 25 April 2016

How To: Get a "Back To Top" button on blogger

Every now and again I'll decide that I fancy changing something about my blog, this time I fancied adding a "Back To Top" button as I thought this would be very useful on my particular template.

Without any thought of how to install a button I created my own and then came to the difficult part of needing to install it. I created my button on PicMonkey which, after PhotoShop, is my favourite editing programme and super easy to use. This is the button I created:

(When creating my button I did make sure that it had a transparent background.)

After making, or choosing, your button you must make sure it has it's own URL to add to the HTML, so I just created a blog post with the picture in, published that post, right-clicked the image to open it in a new tab and then copied the link into the HTML (and then deleted the post).

That HTML is:

<!--Smooth Back to Top Button Start-->

<script>

jQuery(document).ready(function() {

var offset = 220;

var duration = 500;

jQuery(window).scroll(function() {

if (jQuery(this).scrollTop() > offset) {

jQuery('.back-to-top').fadeIn(duration);

} else {

jQuery('.back-to-top').fadeOut(duration);

}

});

jQuery('.back-to-top').click(function(event) {

event.preventDefault();

jQuery('html, body').animate({scrollTop: 0}, duration);

return false;

})

});

</script>

<style>

div#page {

max-width: 900px;

margin-left: auto;

margin-right: auto;

padding: 20px;

}

.back-to-top {

position: fixed;

bottom: 2em;

right: 0px;

text-decoration: none;

color: #7be7b6;

font-size: 12px;

padding: 1em;

display: none;

}

.back-to-top:hover {

text-decoration: none;

}

</style>

<a href="#" class="back-to-top"><img src="Insert URL" / /></a>

<!--Smooth Back to Top Button End-->

To add your own button you will want to delete the pink text and paste your own URL in it's place!

And that is it, I feel as though it sounded more complicated than it is, but if I can do it, you can do it, trust me!