我有五个图像的水平菜单。所有这 5 个图像都处于活动状态和灰色状态。当特定图像处于活动状态时,其余 4 个需要变灰。对于其他图像也是如此。
我是在 jquery 中完成的,而且代码也没有那么优化和好。是这样的
$("document").ready(function(){
$("#imageidone").click(function() {
$("#imageidone").attr("src","/path to image_active");
$("#imageidtwo").attr("src","/path to image_grayed");
$("#imageidthree").attr("src","/path to image_grayed");
$("#imageidfour").attr("src","/path to image_grayed");
$("#imageidfive").attr("src","/path to image_grayed");
});
$("#imageidtwo").click(function() {
$("#imageidone").attr("src","/path to image_grayed");
$("#imageidtwo").attr("src","/path to image_active");
$("#imageidthree").attr("src","/path to image_grayed");
$("#imageidfour").attr("src","/path to image_grayed");
$("#imageidfive").attr("src","/path to image_grayed"); });
and so on for imageidthree, imageidfour, imageidfive
});
如何使用 CSS sprites 或更紧凑的 jqueryish 方式以更好的方式做到这一点,
谢谢你