我在我的一个模板中使用了此片段进行平滑滚动。来源:http://css-tricks.com/snippets/jquery/smooth-scrolling/
<script>
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
&& location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
</script>
但这会导致我的Twitter Bootstrap Modal的javascript代码出现问题(模态不会显示):
<!-- Modal -->
<script>
$(function() {
$("input#submitt").click(function(){
$.ajax({
type: "POST",
url: "process.php",
data: $('form#contact').serialize(),
success: function(msg){
alert("success: " + msg);
$("#form-content").modal('hide');
},
error: function(){
alert("failure");
}
});
});
});
</script>
如果我删除Smooth Scrolling代码,我的模态就可以了。我正在寻找平滑滚动的替代方案或现有方法的任何改进。