I'm pretty inexperienced with JavaScript and am using a template. Cannot seem to figure out why this error appears in Internet Explorer. It works in every other browser.
$('.navbar a, .navbar li a, .brand, #footer li a, .more a, a.go-top')
.bind('click', function(event) {
var $anchor = $(this),
scrollVal = $($anchor.attr('href')).offset().top - 60;
if (scrollVal < 0) {
scrollVal = 0;
}
$('[data-spy="scroll"]').each(function() {
$(this).scrollspy('refresh');
});
$.scrollTo(scrollVal, {
easing: 'easeInOutExpo',
duration: 1500
});
event.preventDefault();
});
Any ideas why this is happening?
I'm pretty inexperienced with JavaScript and am using a template. Cannot seem to figure out why this error appears in Internet Explorer. It works in every other browser.
$('.navbar a, .navbar li a, .brand, #footer li a, .more a, a.go-top')
.bind('click', function(event) {
var $anchor = $(this),
scrollVal = $($anchor.attr('href')).offset().top - 60;
if (scrollVal < 0) {
scrollVal = 0;
}
$('[data-spy="scroll"]').each(function() {
$(this).scrollspy('refresh');
});
$.scrollTo(scrollVal, {
easing: 'easeInOutExpo',
duration: 1500
});
event.preventDefault();
});
Any ideas why this is happening?
Share Improve this question edited Jun 9, 2014 at 16:30 enter_the_natrix asked Jun 9, 2014 at 15:08 enter_the_natrixenter_the_natrix 511 silver badge4 bronze badges 5-
1
$($anchor.attr('href'))
doesn't find any matching element. You need to do some debugging. What is the value of$anchor.attr("href")
? Is it a tag name? When you get errors, useconsole.log()
to confirm that the values in your program are what you expect. – cookie monster Commented Jun 9, 2014 at 15:10 - 2 And are you saying it works in other browsers, just not IE11? You have almost enough information in your question for it to be answered, but not quite. Most questions dealing with DOM selection will need to include the HTML used to create the DOM. – cookie monster Commented Jun 9, 2014 at 15:15
- Well there are multiple links that use the scroll function in the html page... I can't really put in the entire page can I? – enter_the_natrix Commented Jun 9, 2014 at 16:31
- 1 What you need to do is first debug, and then if you still can't figure it out, show the results of your debugging in the question, and narrow the HTML and JS down to a minimal example that successfully demonstrates the issue. – cookie monster Commented Jun 9, 2014 at 16:35
- @Ejay give me a break please I am working on it. :( – enter_the_natrix Commented Jun 9, 2014 at 17:14
1 Answer
Reset to default 3the error you are seeing is in the line 4
scrollVal = $($anchor.attr('href')).offset().top - 60;
it is a monly because you are trying to use a propierty of an object and it is undefined.
in your case $($anchor.attr('href')).offset() is probably undefined, you need to see if $anchor is undefined or it not have the propierty href so it can't have the ofset
you can use developer tools (F12) and a breack point to inspect the values.
you can learn how to do it in: how to use console
good luck
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745361222a4624368.html
评论列表(0条)