1 reply [Last post]
Snefferdy
Snefferdy's picture
Offline
newbie
Canada
Last seen: 1 year 11 weeks ago
Canada
Timezone: GMT-4
Joined: 2022-03-09
Posts: 1
Points: 2

I'm creating a website using a builder (Divi). I just need a bit of CSS code to scale and position one element (a video), but the only code I know is JS. I was wondering if anyone can help me translate it into CSS. Here's the JS code:

var browserW = window.innerWidth;
var browserH = window.innerHeight;
var yPosOrigin = ORIGINAL POSITION;

var aspect = browserW/browserH;
if (aspect > 1 && aspect < 2) {
vidW = browserH*2;
} else {
vidW = linear(aspect, 1, 2, (browserW*2), browserW);
}
vidSca = vidW/1920*100;
if (aspect > 2) {
yPos = yPosOrigin+((browserH-(960*(vidSca/100)))/2);
} else {
yPos = yPosOrigin;
}

The three first lines are just setting variables. In the end, I want the video to be scaled at vidSca(%) and the vertical position adjusted by yPos (pixels).

Any advice? Thanks!

thepineapplehead
thepineapplehead's picture
Offline
Moderator
Last seen: 1 year 6 weeks ago
Timezone: GMT+1
Joined: 2004-06-30
Posts: 9683
Points: 819

This may be a silly question,

This may be a silly question, but why do you need to do it with CSS? Can you not use your existing Javascript to achieve what you need?

Verschwindende wrote:
  • CSS doesn't make pies