简体   繁体   中英

How to add custom image to a button (dojo 1.7)

How do I add a custom image to a dojo button

here is the sample code for button without image

<div id="zoomin" data-dojo-type="dijit.form.Button">
    <span>zoomin</span>
</div>

These answers are close, but the style definition for your icon must include the following:

.myIcon {
  background-image: url(...);
  background-repeat: no-repeat;
  width: 16px;
  height: 16px;
  text-align: center;
}

You can set an icon class on your widget and then provide the image in css.

<div id="zoomin" data-dojo-type="dijit.form.Button" iconClass="myIcon">
    <span>zoomin</span>
</div>

.myIcon {
  background-image:  url(...);
}

http://dojotoolkit.org/reference-guide/1.7/dijit/form/Button.html#change-the-icon

follow Craig's answer but to conform with 1.7+ and html standards, instead use

<div id="zoomin" data-dojo-type="dijit.form.Button" data-dojo-props="iconClass:'myIcon'">
    <span>zoomin</span>
</div>

Or you can decide which through a function override

<div id="zoomin" data-dojo-type="dijit.form.Button">
    <script type="dojo/method" data-dojo-event="getIconClass">
         var regular = this.inherited(arguments);
         // this evaluation will allways be true, but here for sake of argument
         return (this.declaredClass == 'dijit.form.Button' ? "myButtonIcon" : regular);
    </script>
    <span>zoomin</span>
</div>

I use dojo 1.10 and working with using background-repeat:round

<div id="zoomin" data-dojo-type="dijit/form/Button" iconClass="myIcon">
<span>zoomin</span>

.myIcon {
 background-image:  url(...);
 background-repeat: round;
 width: 18px;
 height: 18px;
 text-align: center;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM