图像悬停缩放延迟像谷歌图像

image hover zoom DELAY like google images

本文关键字:图像 谷歌 缩放 悬停 延迟      更新时间:2023-09-26

我从一个视频教程中编写了js代码,但在动画之前没有延迟。我已经尝试了很多方法与delay()和setTimeout(),但没有得到所需的结果…

如果有人能帮我?请做吧:)

我很感激。

下面是可以编辑和在线运行的代码:http://jsfiddle.net/S2svG/

下面是js代码:

$(function(){
    $.fn.popOut=function(user_opts){            
        return this.each(function(){
            var opts=$.extend({
                useId:"poppedOut",
                padding:20,
                border:0,
                speed:200
            },user_opts);
            $(this).mouseover(function(){
                // kill any instance of this already
                $("#"+opts.useId).remove();
                // make a copy of the hovered guy
                var $div=$(this).clone();
                // setup for prelim stuff
                $div.css({
                    "position":"absolute",
                    "border":opts.border,
                    "top":$(this).offset().top,
                    "left":$(this).offset().left,
                    "-moz-box-shadow":"0px 0px 12px black",
                    "-webkit-box-shadow":"0px 0px 12px black",
                    "z-index":"99"
                });
                // store all of the old props so it can be animate back
                $div.attr("id",opts.useId)
                    .attr("oldWidth",$(this).width())
                    .attr("oldHeight",$(this).height())
                    .attr("oldTop",$(this).offset().top)
                    .attr("oldLeft",$(this).offset().left)
                    .attr("oldPadding",$(this).css("padding"));
                // put this guy on the page
                $("body").prepend($div);
                // animate the div outward
                $div.animate({
                    "top":$(this).offset().top-Math.abs($(this).height()-opts.height),
                    "left":$(this).offset().left-opts.padding,
                    "height":opts.height,
                    "padding":opts.padding
                },opts.speed);
                // loop through each selector and animate it to its css object
                for(var eachSelector in opts.selectors){
                    var selectorObject=opts.selectors[eachSelector];
                    for(var jquerySelector in selectorObject){
                        var cssObject=selectorObject[jquerySelector];
                        $div.find(jquerySelector).animate(cssObject,opts.speed);
                    }
                }
                $div.mouseleave(function(){
                    $("#"+opts.useId).animate({
                        width:$(this).attr("oldWidth"),
                        height:$(this).attr("oldHeight"),
                        top:$(this).attr("oldTop"),
                        left:$(this).attr("oldLeft"),
                        padding:$(this).attr("oldPadding")
                    },0,function(){
                        $(this).remove();
                    });
                });
            });
        });
    };
        $(".productBox").popOut({
            height:300,
            border:"1px solid #333",
            selectors:[{
                ".productDescription":{
                    height:150
                }
            }]
        });                    
});     

这是你需要的吗?

http://jsfiddle.net/S2svG/48/

欢呼

如果你想要鼠标悬停事件和动画之间的延迟,你可能需要看看hoverIntent jQuery插件:

hoverIntent是一个插件,它试图确定用户的意图……像一个水晶球,只有用鼠标移动!它的工作原理是(并衍生自)jQuery的内置悬停。然而,与其它会立即调用onMouseOver函数,直到用户的鼠标在呼叫前足够慢

说了这么多,你可能想看看jQuery.delay()演示