2015-06-18 108 views
1

我想要將圖像的背景大小更改爲用戶所需的寬度和高度。用jquery更改背景大小

我有一個形式,其中用戶可以輸入正確的寬度和高度

<input type="text" class="form-control input-width input-px" maxlength="2" name="width">PX breed 
    <input type="text" class="form-control input-height input-px" maxlength="2" name="height">PX hoog 

並且如果輸入改變我想的背景大小更改爲所述輸入字段的值

 $(".input-px").on("change", function() 
     { 

      width = $(".input-width").val()+"px"; 
      height = $(".input-height").val()+"px" 

      $(".source").css("background-size", width + height); 

     }) 

我沒有得到任何錯誤,但它也沒有改變寬度/高度。

回答

3

我認爲你應該做如下:

$(".source").css("background-size", width + ', ' + height); 

你正在做它,你正在做的寬度和高度的總和的方式,在CSS中,背景大小需要用逗號分隔的兩個數字。

1

我認爲你在背景大小的文本輸入中缺少一個空格。

$(".source").css("background-size", width + " " + height);