javascript - 在调整窗口大小时更改 skewY Angular

标签 javascript html css getuikit

请不要使用 jQuery 和 SCCS(即使我在这里使用 UIkit3 进行样式设置)。导航栏有一个倾斜的背景图像,这是通过 CSS 中的线性渐变和固定高度完成的。我的方法是使用 transform: skewY 并在调整大小时更改 Angular 值。 我可以在控制台中看到值发生变化,但它似乎不会影响站点。

window.onresize = function(event) {
w = window.innerWidth;
h = 140;
document.getElementById('Rhombus').style.transform="skewY('-Math.atan(h/w)*180/Math.PI )+'deg)";

alpha = Math.atan(h/w)*180/Math.PI;
console.log(w, h, -alpha);
};

Codepen

下面的容器 #Rhombus 也应该使用与标题相同的 Angular 。

最佳答案

我实际上通过使用 CSS 变量并在 JS 中更新它们找到了解决方案:

window.onresize = function(event) {
root = document.documentElement;
w = window.innerWidth;
h = 140;
alpha = Math.atan(h/w)*180/Math.PI;
document.getElementById('Rhombus').style.transform="skewY(`${-alpha}deg`)";
console.log(w, h, -alpha);
root.style.setProperty('--atan', -alpha + "deg");
root.style.setProperty('--tan', alpha + "deg");
};

关于javascript - 在调整窗口大小时更改 skewY Angular ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57125589/

相关文章:

html - 从右向左旋转菜单幻灯片

javascript - 如何将这些数组值全部打印成 html 表单?

jquery - 仅在iphone/ipad 上的网站图库onclick 有错误

javascript - 使用 jQuery/JavaScript Div 到图像

javascript - 有没有办法用三元运算符在 html 元素中切换 css 类?

javascript - Cordova 应用程序中的 Hammer.js 事件仅在第二次尝试时触发

javascript - Date.js 中一周的第一天 - 星期一

html - 如何对齐图片和文字

html - 我的行内 block 元素没有正确排列

css - 为众多背景图像之一添加不透明度