$(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.
});
});
答案 0 :(得分:2)
我认为有几种方法可以做到,试试;
var currentWidth = $this.width();
var newWidth = currentWidth * 1.1; //increment by 10%
//OR
var newWidth = currentWidth + ( currentWidth * 10) / 100; //increment by 10%
希望这有帮助。
答案 1 :(得分:2)
您只需将新宽度设置为旧宽度+旧宽度的10%:
var newWidth = currentWidth + (currentWidth * 0.1);
答案 2 :(得分:1)
尝试用var newWidth = currentWidth * 1.1;