我有兩個相互衝突的javascript文件。一種是打開模式並使用像<a href="#modal" data-toggle="modal">open modal</a>
這樣的鏈接,然後打開模式id="modal"
。但另一個腳本是用於平滑滾動的,它會從url (I'd like to keep that part!)
中刪除錨點,但在添加平滑滾動腳本後,模塊不起作用。任何想法如何解決它?什麼是分離JavaScript功能的最佳方式?
modal.js:
$(".modal-wide").on("show.modal", function() {
var height = $(window).height() - 200;
$(this).find(".modal-body").css("max-height", height);
});
$('a[data-toggle="modal"]').bind('click',function(){
$('.modal').modal('hide');
});
scroll.js:
$(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
}, 500);
return false;
}
}
});
});
scroll.js來源:https://css-tricks.com/snippets/jquery/smooth-scrolling/
它是自舉模式嗎?版本3? – amenadiel
@amenadiel我真的不知道我從哪裏得到的模態代碼,但我相信它是從bootstrap 3.0是 –