3 回答
TA贡献1831条经验 获得超10个赞
function setStyle(e, a) {
var i;
for (i in a) {
e.style[i] = a[i]
}
}
function changeIcon(index) {
var home = document.getElementsByClassName('iconhome_act')[0],
server = document.getElementsByClassName('iconservice')[0],
user = document.getElementsByClassName('iconuser')[0];
switch (index) {
case 0:
setStyle(home, {
backgroundImage : "url('index/myImg/t_icon_home_active.png')"
})
setStyle(user, {
backgroundImage : "url('index/myImg/t_icon_user.png')"
});
setStyle(server, {
backgroundImage : "url('index/myImg/t_icon_service.png')"
});
break;
case 1:
setStyle(home, {
backgroundImage : "url('index/myImg/t_icon_home.png')"
})
setStyle(user, {
backgroundImage : "url('index/myImg/t_icon_user.png')"
});
setStyle(server, {
backgroundImage : "url('index/myImg/t_icon_service_active.png')"
});
break;
case 2:
setStyle(home, {
backgroundImage : "url('index/myImg/t_icon_home.png')"
})
setStyle(user, {
backgroundImage : "url('index/myImg/t_icon_user_active.png')"
});
setStyle(server, {
backgroundImage : "url('index/myImg/t_icon_service.png')"
});
break;
}
}
我这里的index是外层函数传递的索引值
TA贡献1844条经验 获得超8个赞
js
{
data() {
{
currentIndex: 0,
items: ['f.png', 'u.png', 's.png', 'p.png']
}
},
methods: {
getSrc(i) {
var src = this.items[i]
if (i === this.currentIndex) {
src = src.replace(/(?=.\.png)/, '_')
}
return src
}
}
}
template
<img v-for="(item,i) of items" :src="getSrc(i)" @click="currentIndex=i"/>
添加回答
举报