Can anyone help explain why my function is not working?

The section below is HTML

<title>Movie Design</title>


Line 15 <body onload="expandingWindow()">
Javascript Section
Line 38  function expandingWindow() {
  var heightspeed = 10;
  var widthspeed = 10;
  var leftdist = 0;
  var topdist = 0;
  var winwidth = window.screen.availWidth - leftdist;
  var winheight = window.screen.availHeight - topdist;
  for (sizeheight = 1; sizeheight < winheight; sizeheight += heightspeed) {
    self.resizeTo("1", sizeheight);
  }
  for (sizewidth = 1; sizewidth < winwidth; sizewidth += widthspeed) {
    self.resizeTo(sizewidth, sizeheight);
  }
}

Can anyone tell me why the “function expandingWindow()” is not working?
Please check the codes in the Codepen

What’s self? There isn’t a variable called self anywhere in your code.

There may be other issues, but on phone so can’t really check much more than that atm

1 Like

Hello,
I want to add on from the previous posters message. You may be referring to the this keyword, instead of self.

Funny to still discover new things, I never knew there was a global property self on the window object. But anyway, I think you can achieve the effect you’re looking for very easily with CSS with an animation:

body {
  transform:scale(0);
  animation:grow 3s forwards;
}

@keyframes grow {
  to {
    transform:scale(1)
  }
}

Thank you for the replies from all of you.

I don’t think there is a difference between window and self in this case (didn’t really check). Usually, when people use self they have assigned it the this value from a different scope.

Also, you are not calling the function anywhere. I would assume it is meant to be used as a resize handler or something?

window.addEventListener('resize', expandingWindow)

Edit: Oh it’s called onLoad


On MDN it has this note for resizeTo

Note: It’s not possible to resize a window or tab that wasn’t created by window.open(). It’s also not possible to resize when the window has multiple tabs.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.