【问题标题】:Change background-size with jquery使用 jquery 更改背景大小
【发布时间】:2015-06-18 14:48:07
【问题描述】:

我想将图像的背景大小更改为用户想要的宽度和高度。

我有一个表单,用户可以在其中输入正确的宽度和高度

   <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 );

      })

我没有收到任何错误,但它也不会改变宽度/高度。

【问题讨论】:

    标签: jquery background-size


    【解决方案1】:

    我认为你应该这样做:

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

    你这样做的方式,你是在做宽度和高度的总和,在 css 中,背景大小需要 2 个用逗号分隔的数字。

    【讨论】:

      【解决方案2】:

      我认为您在背景大小的文本输入中缺少空格。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-05-04
        • 2013-08-30
        • 2011-06-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多