jquery를 사용하여 rect의 너비와 높이를 설정하려고하지만 "Uncaught TypeError : Cannot read property 'scrollWidth'of null" 오류가 발생합니다 .
다음은 내 코드입니다.
$(document).ready(function() {
var winw = $(document).width();
var winh = $(document).height();
$("#mask > rect").width(winw);
$("#mask > rect").height(winh);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="0" height="0">
<defs>
<mask id="mask">
<rect x="0" y="0" width="1920" height="1024" fill="#ff0000" fill-opacity=".75" />
<circle r="140" cx="240" cy="240" fill="#000" fill-opacity="1" stroke="none" />
</mask>
</defs>
</svg>
시도 attr()
$(document).ready(function() {
var winw = $(document).width();
var winh = $(document).height();
console.log('before-width:'+$("#mask > rect").attr('width'))
console.log('before-height:'+$("#mask > rect").attr('height'))
$("#mask > rect").attr('width' , winw);
$("#mask > rect").attr('height',winh);
console.log('after-width:'+$("#mask > rect").attr('width'))
console.log('after-height:'+$("#mask > rect").attr('height'))
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="0" height="0">
<defs>
<mask id="mask">
<rect x="0" y="0" width="1920" height="1024" fill="#ff0000" fill-opacity=".75" />
<circle r="140" cx="240" cy="240" fill="#000" fill-opacity="1" stroke="none" />
</mask>
</defs>
</svg>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다