使用jQuery按百分比增加元素宽度
Increase element width by percentage using jQuery
这个答案由Varinder工作得很好,但我想得到的元素宽度设置在像素和增加10%。
$(window).load(function() {
$(".ml").each(function() { // this is kindof sugary way of doing for loop over array of elements - which is $(".ml")
var $this = $(this); // the current jQueried .ml element
var currentWidth = $this.width(); // get width of current element, width is a jQuery method: https://api.jquery.com/width/
var newWidth = currentWidth + 5; // increment the width
$this.width(newWidth); // pass in the new width as the parameter.
});
});
我想有几种方法可以做到这一点,试试;
var currentWidth = $this.width();
var newWidth = currentWidth * 1.1; //increment by 10%
//OR
var newWidth = currentWidth + ( currentWidth * 10) / 100; //increment by 10%
尝试将currentWidth替换为var newWidth = currentWidth * 1.1;
你只需要设置新宽度为旧宽度+旧宽度的10%:
var newWidth = currentWidth + (currentWidth * 0.1);
相关文章:
- 根据元素高度和宽度的百分比变化增加或减少字体大小
- javascript函数,它将数组作为输入,将每个数组元素增加1,并返回增加值的新数组
- 增加一个元素's值
- jQuery根据元素的数量增加数量
- 增加在选择元素HTML中搜索的时间
- 增加新<李>仅由有序列表创建的元素<ol>
- Div 高度不会在附加任何元素时增加
- 如何在 AngularJS 中动态增加/减少段落元素的高度
- 使用函数按间隔调用自身,增加变量,并设置 id 等于该变量的元素的类值
- 如何在鼠标悬停和鼠标出出时增加选择元素的大小时固定表格的位置
- 为什么 JavaScript 中元素的宽度没有增加
- 如何在不使用任何循环的情况下增加元素的宽度
- 在滚动野生动物园错误上增加元素的高度
- 当用户向下滚动页面时增加元素不透明度
- jQuery-增加显示的元素
- 增加/减少页面上所有元素字体大小的有效方法
- 为什么每次删除和重新创建目标元素时动画速度都会增加
- 增加/减少滚动时的元素填充
- ReactJS中计数器增加的显示元素
- 更改哪个元素增加JavaScript