async function setLatexSize(arr_latexImg, fontSize) {
for (let i = 0;i< arr_latexImg.length;i++){
let newImg = new Image()
newImg.src = arr_latexImg[i].src
await new Promise((resolve) => {
newImg.onload = function() {
arr_latexImg[i].height = fontSize * newImg.height / 16
arr_latexImg[i].width = fontSize * newImg.width / 16
arr_latexImg[i].setAttribute('width', fontSize * newImg.width / 16);
arr_latexImg[i].setAttribute('height', fontSize * newImg.height / 16);
resolve()
}
})
}
}
我想跟踪字号的改变来设置图片的宽高,通过for循环遍历每一个img元素,之后通过onload里面来设置img元素的宽高,但是现在的问题是当我console出arr_latexImg[i]
的时候,他标签上面是有宽高属性的,但是我页面中的元素本身依旧是原来的样子,没有变化
上面是页面中的元素标签,下面的图是我在console中显示的arr_latexImg[0]
,arr_latexImg[0]
中的属性是设置上了,但是元素本身一九没有,arr_latexImg
这个数组是通过jq获取元素,完了each一个新的数组,下面是压缩后的代码。我想知道目前的问题是在哪块,是我方法哪块写的有问题吗
t = $("div.table").children().find("img.hex-exe-img"),
r = [];
$.each(t, function(e, n) {
r.push(t[e])
}),