Lynob Lynob - 2 months ago 13
HTML Question

Close modal and scroll to div



$("#contact-form").click(function() {
$('html, body').animate({
scrollTop: $("#contact-section").offset().top
}, 2000);
});

<div class="modal fade" id="saModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h3>title</h3>
</div>
<div class="modal-body">
text
</div>
<div class="modal-footer">
<button type="button" id="contact-form" class="btn btn-default pull-right glyphicon glyphicon-envelope">Contact</button>
</div>
</div>
</div>
</div>

<div id="contact-section">
<?php require 'contact.php'; ?>
</div>





When I click contact, The bootstrap modal closes as expected but doesn't scroll to contact section, why?

Ish Ish
Answer

Don't use the data-dismiss="modal"

<button type="button" id="contact-form" class="btn btn-default pull-right glyphicon glyphicon-envelope" >Contact</button> 

$("#contact-form").click(function() {
    $('#myModal').modal('hide');
    $('html, body').animate({
        scrollTop: $("#contact-section").offset().top
    }, 2000);
});
Comments