喜歡的話題。有些東西不起作用...我想懸停在鏈接上並更改div元素的背景圖像。始終在data-rhomboid-img中設置的不同畫面上。在jQuery中更改mouseover時data-attribute的background-image。
<div id="img-nav-rhomboid" class="nav-rhomboid"></div>
<ul class="menu-list">
<li><a href="#" data-rhomboid-img="img/example1.jpg">A</a></li>
<li><a href="#" data-rhomboid-img="img/example2.jpg">B</a></li>
</ul>
.nav-rhomboid{
background: url(../img/nav-bg.png) no-repeat center center;
display: flex;
align-items: center;
}
$('li a').mouseover(function() {
var rhomboidImg = $(this).data('rhomboid-img');
$('#img-nav-rhomboid').each(function() {
$(this).css('background', $(this).attr(rhomboidImg));
});
});
'$( '#IMG-NAV-菱形')。each'建議你用id'IMG-NAV-rhomboid'一個以上的元素,你永遠不應該有多個要素與相同的ID。 –
是的,我知道。即使我把類導航菱形它不起作用。 – Blosom