当您将鼠标悬停在链接上时,我有这段代码可以更改 div 的背景图像:
<script>
$('.main').on('mouseover', 'a', function () {
var background = "url('" + $(this).attr('data-background') + "')";
$('.main').css('background-image', background)
});
</script>
和随之而来的html..
<div style="background: #f2f2f2 no-repeat center; background-size:100% auto;" class="main">
<div id="logo"></div>
<div class="center-inner">
<h3>
<a href="#" data-background="img/img1.jpg">img1</a>
<a href="#" data-background="img/img2.jpg">img2</a>
<a href="#" data-background="img/img3.jpg">img3</a>
</h3></div>
<div id="copyright"><p>©2013</p></div>
</div>
如何向此代码添加淡入和淡出(鼠标移出)效果?
谢谢!