CSS代码:
.icon {
display: inline-block;
width: 16px; height: 20px;
line-height: 20px;
font-size: 30px;
overflow: hidden;
position: relative;
}
.icon s {
width: 100%; height: 100%;
background-image: url(sprite_icons.png);
position: absolute; left: 0; top: 0;
}
.icon1 s { background-position: 0 0; }
.icon2 s { background-position: -20px 0; }
.icon3 s { background-position: -40px 0; }
.icon4 s { background-position: -60px 0; }
.link { margin-right: 15px; }
.out { color: #34538b; /* 该颜色控制图标的颜色 */}
HTML代码:
更改颜色:<input id="colorInput" type="color" value="#34538b" autocomplete="off">
<p id="colorP" class="out">
<i class="icon icon1"><s></s>█</i><a href="##" class="link">返回</a>
<i class="icon icon2"><s></s>█</i><a href="##" class="link">刷新</a>
<i class="icon icon3"><s></s>█</i><a href="##" class="link">收藏</a>
<i class="icon icon4"><s></s>█</i><a href="##" class="link">展开图片</a>
</p>
JS代码:
var eleInput = document.getElementById("colorInput"),
eleP = document.getElementById("colorP");
eleInput.onchange = function() {
eleP.style.color = this.value;
};