I'm getting this error around both the "var" definition inside the event listener. Vs code suggests to add { and, again and again but nothing gets fixed.
Also Vs code suggests me to use '{'>'}' instead of =>
<script> let path = document.querySelector ('path') let pathLength = path.getTotalLength() path.style.strokeDasharray = pathLength + ' ' + pathlength; path.style.strokeDashoffset = pathLength; //I get error for "=>" in the following window.addEventListener('scroll',() => { //I get errors for both of these vars var:scrollPercentage =(document.documentElement.scrollTop+document.body.scrollTop)/(document.documentElement.scrollHeight-document.documentElement.clientHeight) var:drawLength = pathLength*scrollPercentage path.style.strokeDashoffset = pathLength-drawLength }) </script>
You are putting colons after the var and that is not valid javascript syntax. It should be:
<script>
let path = document.querySelector ('path')
let pathLength = path.getTotalLength()
path.style.strokeDasharray = pathLength + ' ' + pathlength;
path.style.strokeDashoffset = pathLength;
//I get error for "=>" in the following
window.addEventListener('scroll',() => {
//I get errors for both of these vars
var scrollPercentage =(document.documentElement.scrollTop+document.body.scrollTop)/(document.documentElement.scrollHeight-document.documentElement.clientHeight)
var drawLength = pathLength*scrollPercentage
path.style.strokeDashoffset = pathLength-drawLength
})
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.