I followed a tutorial to add a "back-to-top" button, and it works on my JSFiddle but not on my live page. The button shows up in Safari but doesn't scroll up. Any ideas why?
// Contact Form
$(document).ready(function() {
$("#contactfrm").submit(function(e) {
e.preventDefault();
var name = $("#name").val();
var email = $("#email").val();
var message = $("#message").val();
// Email validation code here
if (isValidEmail(email) && (message.length > 1) && (name.length > 1)) {
// Ajax call to send form data
} else {
$('.error').fadeIn(1000);
}
return false;
});
});
// Smooth scrolling
$(document).ready(function() {
$('a[href^="#"]').on('click', function (e) {
e.preventDefault();
// Scroll animation here
});
});
// Back-to-Top Button
$(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;
})
});