marilynn.fowler
07-13-2012, 01:35 AM
I have a script that I got from W3Schoolsh that lets me show/hide my menu. It works fine until I add the doctype, then it ceases to function. I realize I could redo it with jQuery, but I'm more interested in WHY the addition of a doctype would cause it to stop working. Here is the code:
<script type="text/javascript">
var i = -135;
var c = 0;
var intHide;
var navSpeed = 5;
function choosePic() {
if (window.innerWidth < 600) {
document.getElementById('nav').onclick = showHideNav;
document.getElementById("logo").src = "images/grot_white.png";
document.getElementById("tagline").src = "images/tagline_phone.png";
document.body.style.backgroundColor = "#194964";
}
}
function showHideNav() {
if (c == 0) {
c = 1;
clearInterval(intHide);
intShow = setInterval("showNav()",10);
}
else {
c = 0;
clearInterval(intShow);
intHide = setInterval("hideNav()",10);
}
}
function showNav() {
if (i < -12) {
i = i + navSpeed;
document.getElementById('nav').style.left=i;
}
}
function hideNav() {
if (i > -150) {
i = i - navSpeed;
document.getElementById('nav').style.left=i;
}
}
</script>
The original script had a simple <html> and no doctype.
<script type="text/javascript">
var i = -135;
var c = 0;
var intHide;
var navSpeed = 5;
function choosePic() {
if (window.innerWidth < 600) {
document.getElementById('nav').onclick = showHideNav;
document.getElementById("logo").src = "images/grot_white.png";
document.getElementById("tagline").src = "images/tagline_phone.png";
document.body.style.backgroundColor = "#194964";
}
}
function showHideNav() {
if (c == 0) {
c = 1;
clearInterval(intHide);
intShow = setInterval("showNav()",10);
}
else {
c = 0;
clearInterval(intShow);
intHide = setInterval("hideNav()",10);
}
}
function showNav() {
if (i < -12) {
i = i + navSpeed;
document.getElementById('nav').style.left=i;
}
}
function hideNav() {
if (i > -150) {
i = i - navSpeed;
document.getElementById('nav').style.left=i;
}
}
</script>
The original script had a simple <html> and no doctype.