我正在慢慢学习如何从头开始修改和编写jQuery,并且一直在尝试修改一些预先编写的代码,这只会使图像不透明:1和同一HTML元素中的所有其他图像不透明度:0.2。
当我使用fadeTo并快速移动图像时,它将停止动画并挂起一段时间,直到它自行修复。任何人都可以就这种情况提出建议。
对不起有点茫然:)
以下是代码:
$(window).load(function(){
var spotlight = {
// the opacity of the "transparent" images - change it if you like
opacity : 0.2,
/*the vars bellow are for width and height of the images so we can make
the <li> same size */
imgWidth : $('#portfolio ul li').find('img').width(),
imgHeight : $('#portfolio ul li').find('img').height()
};
//set the width and height of the list items same as the images
$('#portfolio ul li').css({ 'width' : spotlight.imgWidth, 'height' : spotlight.imgHeight });
//when mouse over the list item...
$('#portfolio ul li').hover(function(){
//...find the image inside of it and add active class to it and change opacity to 1 (no transparency)
$(this).find('img').addClass('active').fadeTo('fast', 1);
//get the other list items and change the opacity of the images inside it to the one we have set in the spotlight array
$(this).siblings('li').find('img').fadeTo('fast', 0.2);
//when mouse leave...
}, function(){
//... find the image inside of the list item we just left and remove the active class
$(this).find('img').removeClass('active');
});
//when mouse leaves the unordered list...
$('#portfolio ul').bind('mouseleave',function(){
//find the images and change the opacity to 1 (fully visible)
$(this).find('img').fadeTo('fast', 1);
});
});