dimanche 19 avril 2015

Cannot Read Property 'top' occurs when click button to open modal window

The following code works when the page loads. However when I click on a button that is supposed to open a modal window I get the following error:


Uncaught TypeError: Cannot read property 'top' of undefined


How can I fix this error?



if ($(window).width() > 992) {

(function($) { "use strict";
$(".page-scroll a[href^='#'], #intro a").on('click', function(e) {
e.preventDefault();
var hash = this.hash;
$('html, body').stop().animate({
scrollTop: $(hash).offset().top - 100}, 2000, 'easeOutExpo');
});
})(jQuery);

$('body').scrollspy({
target: '.navbar',
offset: 110
});
// alert("large");
}
else {

(function($) { "use strict";
$(".page-scroll a[href^='#'], #intro a").on('click', function(e) {
e.preventDefault();
var hash = this.hash;
$('html, body').stop().animate({
scrollTop: $(hash).offset().top - 50}, 2000, 'easeOutExpo');
});
})(jQuery);

$('body').scrollspy({
target: '.navbar',
offset: 70
});
// alert("small");
}

//modal popup function
function popup_modal(item){
var link = $(item).attr('id');
$('#bootstrap_modal').load('/'+link+'');
$('#bootstrap_modal').modal('show');
$("#bootstrap_modal").on("show", function () {
$("body").addClass("modal-open");
}).on("hidden", function () {
$("body").removeClass("modal-open")
});
}

//Modal pop up
$('.mmodal').on('click', function(){
popup_modal(this);
});

Aucun commentaire:

Enregistrer un commentaire