2016-06-11 3 views
0

동적 크기 조정을 사용하려고합니다. 나는 약간의 자바 스크립트를 알고 있지만 아주 새로운 것이다. index.html을 : 나는 다음과 같은 오류가 점점 오전 20 catch되지 않은 형식 오류 : 널 (null)의자바 스크립트 이미지 맵 크기 조정 문제

이 오류는 라인입니다 재산 'getElementsByTagName'을 읽을 수 없습니다 : 지역 = map.getElementsByTagName ('영역'),

감사합니다 스크립트에 대한 티무 내가 볼 수있는 첫 번째 문제는 Dynamically resizing Image-maps and images

<html> 

<head> 
<link rel="stylesheet" type="text/css" href="PB.css"> 

</head> 

<body> 

<script> 

window.onload = function() { 
    var ImageMap = function (map) { 
      var n, 
       areas = map.getElementsByTagName('area'), 
       len = areas.length, 
       coords = [], 
       previousWidth = 1280; 
      for (n = 0; n < len; n++) { 
       coords[n] = areas[n].coords.split(','); 
      } 
      this.resize = function() { 
       var n, m, clen, 
        x = document.body.clientWidth/previousWidth; 
       for (n = 0; n < len; n++) { 
        clen = coords[n].length; 
        for (m = 0; m < clen; m++) { 
         coords[n][m] *= x; 
        } 
        areas[n].coords = coords[n].join(','); 
       } 
       previousWidth = document.body.clientWidth; 
       return true; 
      }; 
      window.onresize = this.resize; 
     }, 
     imageMap = new ImageMap(document.getElementById('planetbobmap')); 
    imageMap.resize(); 
    return; 
} 

</script> 

<img src="Planet Bob.jpg" alt="PlanetBob" usemap="#planetbobmap" border="0" width="1280" height="720" /> 
<map name="planetbobmap"> 
    <area shape="rect" coords="190,140,435,200" alt="skills" href="Skills.jpg" target="_blank" /> 
    <area shape="rect" coords="890,140,1250,200" alt="projects" href="Projects.jpg" target="_blank" /> 
    <area shape="rect" coords="50,460,440,525" alt="schooling" href="Schooling.jpg" target="_blank" /> 
    <area shape="rect" coords="900,460,1230,525" alt="contact" href="Contact.jpg" target="_blank" /> 
    <area shape="circle" coords="652,352,162" alt="Resume" href="Robert J Norton Resume.pdf" target="_blank" /> 
</map> 

</body> 

</html> 

답변

0

, 당신은 정의되지 않은지도 요소 속성 ID에 있기 때문에 document.getElementById를 ('planetbobmap')

를 사용하여지도 요소에 액세스 할 수 없습니다 .

이 HTML 변경을 사용해보십시오.

<map id = "planetbobmap" name="planetbobmap"> 
+0

'map'은'function (map)'호출에 정의되어 있지 않습니다 ... –

+0

글쎄, 한 가지 문제가 수정되었습니다. 스크립트가 여전히 이미지 맵을 변경하지 않는 것 같습니다. 지도 ID를 추가 한 후에도 검사에 오류가 표시되지 않습니다. –