jQuery設定點選選中樣式,onmouseover和onmouseout事件
阿新 • • 發佈:2020-12-02
1、點選選中設定樣式
1 //預設選中第一個 2 $('.navigation>a:first-child>div').addClass('category-selected'); 3 //選中樣式切換 4 $('.navigation>a>div').click((e => { 5 $('.navigation a>div').removeClass('category-selected'); 6 $(e.target).addClass('category-selected'); 7 }));
2、onmouseover和onmouseout事件
- img標籤
1 /** 2 * 滑鼠懸浮 3 * @param id 4 * @param imgOver 5 */ 6 function setFootImgOver(id, imgOver) { 7 $("#footImgLogo" + id).attr('src', imgOver); 8 } 9 10 /** 11 * 滑鼠移除 12 * @param id 13 * @param imgOut 14 */ 15 function setFootImgOut(id, imgOut) { 16 $("#footImgLogo" + id).attr('src', imgOut);17 }
- backgroud-image標籤
1 /** 2 * 懸浮 3 * @param id 4 * @param imgOver 5 */ 6 function proCategoryImgOver(id, imgOver) { 7 $("#proCategoryImg" + id).css({'background-image': 8 'url(' + imgOver + ')'}); 9 } 10 11 /** 12 * 移除 13 * @param id 14 * @param imgOut 15 */ 16 functionproCategoryImgOut(id, imgOut) { 17 $("#proCategoryImg" + id).css({'background-image': 18 'url(' + imgOut + ')'}); 19 }