javascript - 如何为我的代码实现窗口调整大小事件侦听器?
问题描述
我的网站上有一个自动轮播。当我调整浏览器的大小时,轮播的功能仍然有效,但图像变得扭曲(轮播显示了两张图片中的一些)
这是代码笔: https ://codepen.io/Harrison17/pen/VweamoL
const slideWidth = slides[index].clientWidth;
slide.style.transform = `translateX(${-slideWidth * index}px)`;
我想我需要为调整窗口大小添加一个事件侦听器,但我不确定如何在我的代码中实现它。
解决方案
代码如下:
function onResize() {
var windowWidth = window.innerWidth;
// change the width of images or the carousel based on window width
}
window.onresize = onResize;
希望这可以帮助!
推荐阅读
- r - R,SIRT,中型数据导致错误
- c++ - 如何在编译时捕获 std::variant 持有错误类型?
- python - 无法在 deeplabcut(多动物)上执行“优化 tracklets”
- jointjs - JointJS - 在节点中设置带有端口的项目列表
- java - 有没有更好的方法来查找对象数组的界限?
- node.js - Azure Application Insights 数据和关联错误
- pandas - 使用 groupby 创建一个新的 pandas DataFrame Column
- python-3.x - 请提出减少以下代码计算时间的方法
- sql - 使用 SDK .Net VisualBasic FingerPrint U Are U 4500 验证方法失败时出错
- xcode - 将核心数据中的数据整形为可绘图格式