首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >.hover回调中的jQuery回调

.hover回调中的jQuery回调
EN

Stack Overflow用户
提问于 2012-11-02 02:57:40
回答 2查看 667关注 0票数 0

我试图删除一个附加的元素后,我已经隐藏了鼠标出来的元素。我在.hover回调中的回调做错了什么?

代码语言:javascript
复制
// START OF $(document).ready(function() {

$(document).ready(function ()

$('.custom-right-boxes a').hover(function () {
    $(this).append('<div class="click-here"><b>Click</b><span>Here</span></div>');
    $('.click-here').stop().animate({
        width: '88px',
        height: '58px',
        marginLeft: '-44px',
        marginTop: '-40px'
    }, {
        duration: 300
    });
}, function () {
    $('.click-here').stop().animate({
        width: '0px',
        height: '0px',
        marginLeft: '-0px',
        marginTop: '-0px'
    }, {
        duration: 300
    }),

    function () {
        $('.click-here').remove();
    };
});


// END OF $(document).ready(function() {

});
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-11-02 15:08:08

伙计们,成功了!感谢所有帮助我们的人。基本上,Nelson告诉我的这一点很关键,所以感谢这一点,我也不得不改变:

,{时长: 300 }

简单地说:

,300

然后回调起作用了:-)这是最终的代码(在我做额外的修改之前):

代码语言:javascript
复制
// START OF $(document).ready(function() {

$(document).ready(function () {

$('.custom-right-boxes a').hover(function () {
    $(this).append('<div class="click-here"><b>Click</b><span>Here</span></div>');
    $('.click-here').stop().animate({
        width: '88px',
        height: '58px',
        marginLeft: '-44px',
        marginTop: '-40px'
    }, 300);

}, function () {
    $('.click-here').stop().animate({
        width: '0px',
        height: '0px',
        marginLeft: '-0px',
        marginTop: '-0px'
    }, 300, function () {
        $('.click-here').remove();
    });

});

// END OF $(document).ready(function() {
});
票数 1
EN

Stack Overflow用户

发布于 2012-11-02 03:01:54

在您的代码中修复以下内容:

代码语言:javascript
复制
}, {
        duration: 300
    }),  //--> REMOVE THIS parens

    function () {
        $('.click-here').remove();
    };  //ADD A PARENS HERE, like });

因为您错误地将第三个参数传递给了animate(),即回调函数。做了上面提到的更改,并尝试一下。

这将是更正后的版本:

代码语言:javascript
复制
// START OF $(document).ready(function() {

$(document).ready(function (){

$('.custom-right-boxes a').hover(function () {
    $(this).append('<div class="click-here"><b>Click</b><span>Here</span></div>');
    $('.click-here').stop().animate({
        width: '88px',
        height: '58px',
        marginLeft: '-44px',
        marginTop: '-40px'
    }, {
        duration: 300
    });
}, function () {
    $('.click-here').stop().animate({
        width: '0px',
        height: '0px',
        marginLeft: '-0px',
        marginTop: '-0px'
    }, {
        duration: 300
    },

    function () {
        $('.click-here').remove();
    });
});


// END OF $(document).ready(function() {

});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13183721

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档