I'm using a BootStrap theme in which I have a form at the bottom of page. When submitted and the page reloads, I'm presented page top and thus the form is undesirably off-screen.
HTML Anchor
Using a HTML anchor in the action attribute of the form does not work because certain images take longer to load than it takes the browser to jump to the anchor so I end up further up the page than I should.
jQuery scrollTop
I've opted for using jQuery scrollTop however when I place it within the submit event, the page loads and the scroll does not occur. How can achieve scrollTop after form submission?`
Code
$( window ).load(function() {
$("#someform").submit(function(){
$('html, body').animate({
scrollTop: $("#someid").offset().top
}, 2000);
});
});
Aucun commentaire:
Enregistrer un commentaire