Reputation: 1
My web site works on all browsers except IE8. The following code error on the fourth line of code with position().left
is null or not an object. Has anyone seen an fixed this type of IE8 jQuery bug?
$(".navref").click(function(){
var m = Math.floor(($(window).width()-997)/2);
m = m < 0 ? 0 : m; //if screen is smaller than 997, force align to left
var l = $("#"+$(this).attr('rel')).position().left;
var lt = 200;
if($(this).attr('rel') == 'page1') lt = 400;
l = l+(lt-m);
l = l < 0 ? 0 : l;
//,onAfter:function(){checkScreens()}
$('html, body').stop(true,false).scrollTo(l,2000,{easing:'easeInOutCubic'});
return false;
});
The web site is http://sputtens.com.
Upvotes: 0
Views: 2883
Reputation: 1074266
This tells you that $("#"+$(this).attr('rel'))
is not matching any elements, and so position()
returns null
. If you find out why that is, it should sort it out.
Just change the code to this:
var id = $(this).attr('rel');
var element = $("#"+id);
var l = element.position().left;
...and walk through that with the F12 debugging tools, looking at the id
and comparing it with what you have in the DOM, looking at the result of the query for the element with that ID, etc.
Upvotes: 5