javascript - 使用JS旋转图像时如何添加边距顶部
问题描述
当图像旋转 90 度时,我想在图像顶部添加边距。这就是我旋转图像的方式:
const img = document.querySelector("#mocci-logo")
document.addEventListener("scroll", (e) => {
if(!window.scrollY) {
img.style.transform = "rotate(0deg)"
} else {
img.style.transform = "rotate(-90deg)"
}
})
我知道这可能很简单,但我是初学者。所以希望有人能告诉我如何做到这一点。谢谢!
解决方案
试试这个:
const img = document.querySelector("#mocci-logo")
document.addEventListener("scroll", (e) => {
if(!window.scrollY) {
img.style.transform = "rotate(0deg)"
img.style.marginTop = "0px"; // This can also be 0 or "0".
} else {
img.style.transform = "rotate(-90deg)"
img.style.marginTop = "60px";
}
})
推荐阅读
- asp.net-identity - AddIdentity() fails "InvalidOperationException: Scheme already exists: Identity.Application"
- dht - 如何将 kademlia 路由表表示为数据结构
- python - 如何在 Python 中有效地仅计算此操作的上三角形?
- javascript - 你如何使用嵌入在 Eclipse IDE 中的 EsLint?
- javascript - D3.js 单击以使用 .on() 方法运行
- c++ - 无法在 C++ 中打印字符串
- python - 使用 beautifulsoup 仅解析内部“a”元素中的文本值
- angular - ASP.Net MVC Core:预渲染构建过程未在 50 秒的超时时间内完成
- sql - SQL 排序规则冲突
- haskell - Haskell 中的类型类行为