Answer the question
In order to leave comments, you need to log in
How to resize the animation and paste it in the right place?
Hi Toaster, I'm asking for help from more experienced people in the frontend field. There is a ready-made animation found on codepen.
Link to animation.
You need to insert this animation into your project, in a 200x200 pixel block.
I connected the necessary files, added js, the animation appeared on the site, but the problem is that the animation opens in full screen, and the tag is located at the end of the body document.
My question is:
1. How can I insert this animation into the div I need.
2. How to set the dimensions in the call function of this animation so that it fits into 200x200 pixels.
What was tried:
In the js animation call by the poke method, it was not possible to find the dimensions, although I came across familiar words, for example, these lines:
ArtScene.prototype.setup = function(gl)
{
......
this.fbo = new Fbo({
size: [gl.viewportWidth, gl.viewportHeight]
});
......
}
var pri = new PlanePrimitive({
width: gl.viewportWidth,
height: gl.viewportHeight,
resolution: 1,
flipY: true,
drawMode: Primitive.TRIANGLES,
});
.surface canvas {
width: 200px !important;
height: 200px !important;
}
Answer the question
In order to leave comments, you need to log in
The sizes are knocked down, because the canvas has its own viewport, the dimensions of this viewport are set through the tag attributes. And in CSS, you simply set the dimensions of the DOM element, which has nothing to do with the viewport.
It can be explained by analogies: here you have a modern fullHD TV, and they show an old movie on it. which was filmed in 4:3 format, naturally the film will be stretched in width. Here the movie is the viewport of your canvas, and the TV is the element itself in the DOM.
For the correct image, you need to find where the viewportWidth and viewportHeight are set.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question