【问题标题】:Creating a custom button in firefox (using the custom buttons addon) does not allow me to resize the button image在 Firefox 中创建自定义按钮(使用自定义按钮插件)不允许我调整按钮图像的大小
【发布时间】:2011-07-13 11:05:20
【问题描述】:

我已经在 Firefox 中成功创建了我自己的自定义按钮,它可以满足我的需要。所以然后我通过下面的代码在它上面放置了一个自定义图标(它可以按我的意愿工作),唯一的问题是我的源图像可能比我实际想要的大小更大或更小(以匹配另一个工具栏中的图标)。所以我想要做的是以某种方式将下面代码中的图像调整为硬编码大小,并且可以选择调整为其他按钮图标的大小。

我做了很多谷歌搜索,除了在图像编辑器中调整图像大小并使用调整后的版本之外,我找不到任何可行的解决方案。我下面所有注释掉的代码只是我试图让图像调整大小的一些东西。没有任何效果。

我想知道的另一件事是我在哪里可以找到关于我可以使用哪些功能和属性来制作自定义按钮的好文档。我尝试了自定义按钮网站,文档似乎很少。 IE。在这一点上,我基本上只是在猜测,因为谷歌还没有提出任何我还没有尝试过的好例子。

var profilePath="file:\\" + Components.classes["@mozilla.org/file/directory_service;1"].getService( Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile).path
var myImageDirRelativePath="/testicons/"

var myImage="Next.ico"

this.image=profilePath + myImageDirRelativePath + myImage

//this.style.width=500
//this.style.height=500

//this.width=50
//this.height=40

//this.image.height=5
//this.image.width=5

//this.region=new rect(0px, 24px, 24px, 0px)

我还尝试设置以下属性:

.custombutton                  
  {-moz-image-region: rect( 0px 24px 24px  0px);}

这没用。

【问题讨论】:

    标签: javascript firefox button resize-image


    【解决方案1】:

    看起来您正在调整图像包装器的大小,而不是图像本身。首先创建图像,然后将其附加到正确的位置。

    ​var img = document.createElement('img');​
    img.src = "image.png";
    img.height = 200;
    img.width = 200;
    $('targetwrapper').append(img);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-26
      • 1970-01-01
      • 1970-01-01
      • 2016-02-24
      • 1970-01-01
      • 2016-12-27
      • 1970-01-01
      相关资源
      最近更新 更多