帮助悬停功能

发布于 2024-08-09 10:56:01 字数 939 浏览 7 评论 0原文

任何帮助将不胜感激...

我正在尝试创建彩色照片从黑白淡出的效果。淡入淡出是有效的,但它首先淡出黑白的,这是我不希望的……我喜欢它看起来好像颜色正在显现。然后,一旦它悬停在它上面,就应该恢复到我原来的图形,而它目前根本没有这样做。

除了我上面提到的部分之外,下面的代码可以完美地工作......

//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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不美如何 2024-08-16 10:56:01

您可以为悬停(over,out)事件提供两个函数。您当前仅使用“over”功能。 “out”功能被忽略(因为您没有提供),这就是为什么您看不到淡出效果的原因。

您寻找的效果不起作用,因为淡出效果在调用回调函数之前等待动画完成。您希望两种效果同时执行。

这种效果要实现起来会有点困难。

首先,您必须有 2 个图像元素。一种包含颜色,一种包含黑白图像。

$(this).fadeOut("slow");
$("otherImageElement").fadeIn("slow");

现在。我不会研究一切,但是。执行此操作将在动画期间暂时将“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.

$(this).fadeOut("slow");
$("otherImageElement").fadeIn("slow");

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.

江湖正好 2024-08-16 10:56:01

再次感谢布拉德的输入...我喜欢你处理它的方式...我希望它能够工作:)

它再次产生了一个空白屏幕抱歉...这是我的代码...

          function switch(element) { 
            var originalPath = $(element).attr("src"); 
            var switchToPath = $(element).attr("rel"); 
            $(element).attr({ src: originalPath }); 
            $(element).fadeOut("slow", function() { 
                    $(element).attr({ src: switchToPath }).fadeIn("slow"); 
            } 
        }

      //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( switch(this), switch(this) );
                }
            });
        }

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...

          function switch(element) { 
            var originalPath = $(element).attr("src"); 
            var switchToPath = $(element).attr("rel"); 
            $(element).attr({ src: originalPath }); 
            $(element).fadeOut("slow", function() { 
                    $(element).attr({ src: switchToPath }).fadeIn("slow"); 
            } 
        }

      //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( switch(this), switch(this) );
                }
            });
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文