帮助悬停功能
任何帮助将不胜感激...
我正在尝试创建彩色照片从黑白淡出的效果。淡入淡出是有效的,但它首先淡出黑白的,这是我不希望的……我喜欢它看起来好像颜色正在显现。然后,一旦它悬停在它上面,就应该恢复到我原来的图形,而它目前根本没有这样做。
除了我上面提到的部分之外,下面的代码可以完美地工作......
//Loop through the images and print them to the page
for (var i=0; i < totalBoxes; i++){
$.ajax({
url: "random.php?no=",
cache: false,
success: function(html) {
// following line I originally suggested, but let's make it better...
//$('#bg').append(html).fadeIn('slow');
// also note the fine difference between append and appendTo.
var $d = $(html).hide().appendTo('#bg').fadeIn('slow');
$('img', $d).hover(function() {
var largePath = $(this).attr("rel");
$(this).fadeOut("slow", function() {
$(this).attr({ src: largePath }).fadeIn("slow");
});
});
}
});
}
Any help would be appreciated...
I am trying to create the effect of a colour photo fading through from black and white. The fade in works but its fading the black and white one OUT first which i dont want...id like it to appear as though the colour is coming through. Then once its hovered off of it should revert back to my original graphic which it doesnt currently do at all.
The code below works perfectly apart from the section i mentioned above...
//Loop through the images and print them to the page
for (var i=0; i < totalBoxes; i++){
$.ajax({
url: "random.php?no=",
cache: false,
success: function(html) {
// following line I originally suggested, but let's make it better...
//$('#bg').append(html).fadeIn('slow');
// also note the fine difference between append and appendTo.
var $d = $(html).hide().appendTo('#bg').fadeIn('slow');
$('img', $d).hover(function() {
var largePath = $(this).attr("rel");
$(this).fadeOut("slow", function() {
$(this).attr({ src: largePath }).fadeIn("slow");
});
});
}
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以为悬停(over,out)事件提供两个函数。您当前仅使用“over”功能。 “out”功能被忽略(因为您没有提供),这就是为什么您看不到淡出效果的原因。
您寻找的效果不起作用,因为淡出效果在调用回调函数之前等待动画完成。您希望两种效果同时执行。
这种效果要实现起来会有点困难。
首先,您必须有 2 个图像元素。一种包含颜色,一种包含黑白图像。
现在。我不会研究一切,但是。执行此操作将在动画期间暂时将“otherImageElement”显示在“this”图像元素的右侧。显然不是你想要的。我相信“otherImageElement”必须“相对”于原始图像放置,以便一个出现在另一个之上。
You can provide two functions to the hover(over, out) event. Your currently only utilizing the "over" function. The "out" function is been ignored (as you have not provided one) which is why your not seeing a fadeout effect.
The effect your looking for is not working because the fadeOut effect waits for the animation to complete before it's callback function is called. You want both effects to perform simultaneously.
This effect is going to be a bit harder to accomplish.
First you'll have to have 2 image elements. One contains the color, one contains the b/w image.
Now. I am not going to research everything, but. Doing this will momentarily display the "otherImageElement" to the right of "this" image element during the animation. Obviously not what you want. I believe "otherImageElement" will have to be placed "relative" to the original image so one appears above the other.
再次感谢布拉德的输入...我喜欢你处理它的方式...我希望它能够工作:)
它再次产生了一个空白屏幕抱歉...这是我的代码...
Thanks again Brad for your input...i like the way you approached it...i was hoping it was going to work :)
It produced a blank screen again sorry...here is my code...