Reputation: 169
I have a one page site, and im using the following code for scrolling between the pages:
function gotoPage() {
var cur = $(this);
var role = cur.attr('role');
var target = $('#' + role);
$('html,body').animate({
scrollTop: target.offset().top - 94
}, 1000);
}
$('.navBt').click(gotoPage);
HTML:
<div class="navBt" role="topSpacing">
<img src="img/nav_campaign.png" />
</div>
<div class="navBt" role="sectionD">
<img src="img/nav_club.png" />
</div>
It works perfectly on any browser except IE. When i open it on IE9 (not sure about other versions) it wouldnt work, but once i press F12 to open the inspection, it would start working normally from that point, even if i refresh the page or enter the page again without the inspection opened.
Any ideas why?
Upvotes: 1
Views: 201
Reputation: 4481
this sounds very much like a problem i had a long time ago (with IE only):
are you using console
somewhere in your javascript code? most likely a console.log()
?
then you have got a problem because on IE browsers the console
javascript object doesn't exist until you have opened the development console. so there will be some javascript error (which you can't see cause your console isn't open) which stops the execution of the rest of your javascript code.
this is the workaround I found:
if (!window.console) window.console = {};
if (!window.console.log) window.console.log = function () { };
just put this at the top of your javascript code.
this will create a pseudo console
object and the pseudo method log
, so the errors don't occur with your console
closed.
Upvotes: 1