我想知道你是否可以为我提供一种更好的方法来实现我在这个小提琴中创建的效果:http: //jsfiddle.net/YLuKh/1/
基本上,我想为锚标签的背景颜色设置动画,以显示我通过将锚标签放置在图像顶部的跨度顶部然后悬停动画跨度宽度来完成的图像。任何人都可以提出更直接的方法吗?
HTML
<ul id="test">
<li>
<a href="">This is the link</a>
<span class="bg"></span>
<img src="http://www.ritaxxii.org/wp-content/uploads/Luxury-Bedroom-Furniture-1.jpg" />
</li>
</ul>
JS
$(document).ready(function() {
var li_width = $('#test').find('li').width();
console.log(li_width);
$('#test').find('li').on('mouseover', function() {
$(this).find('.bg').stop().animate({
width: '0'
}, 200);
}).on('mouseout', function() {
$(this).find('.bg').stop().animate({
width: li_width
}, 200);
});
});