百家胎教家园,超级无敌掌门人终极篇,养女 福小清
我想通过js动态设置元素padding-top的百分比值:以下几种都是无法设置成功的:
// setattribute设置padding-top并且转换为百分比 imagebox.setattribute('padding-top',`${(imageheight/imagewidth)*(swiperwidth/imageboxwidth)*100}%`); //setattribute设置padding-top使用percentage imagebox.setattribute('padding-top',`percentage(${(imageheight/imagewidth)*(swiperwidth/imageboxwidth)})`); // style属性直接设置 使用percentage imagebox.style.paddingtop = `percentage${(imageheight/imagewidth)*(swiperwidth/imageboxwidth)}`;
成功实现的方式:
imagebox.style.paddingtop = `${(imageheight/imagewidth)*(swiperwidth/imageboxwidth)*100}%`;
percentage这个百分比用法在css中是起作用的,在js中还是设置css样式的时候还是尽量少用,会出现设置不成功的问题,还是需要转换成百分比。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
css3 flex布局 justify-content:space-between 最后一行左对齐
网友评论