Floating Back to Top

//Call like this:

<?php ter_back_to_top(900,600) ?>

//The Function

/* Back to Top */
function ter_back_to_top($offset = 220, $duration = 500){?>
<a href="#" class="back-to-top rounded-5"><img src="<?php echo TER_CHILD_GRAPHICS ?>top.png" alt="back to top"></a>
<script type="text/javascript">
jQuery(document).ready(function(){
var offset = <?php echo $offset ?>;
var duration = <?php echo $duration ?>;
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>
<?php
}

0 Comments

You must be logged in to post a comment.