我试图在鼠标移出后隐藏元素后删除附加元素。我在.hover回调中的回调做错了什么?
// 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 :(得分:1)
破解它们!感谢所有帮助过的人。基本上尼尔森告诉我的一点是至关重要的,所以,谢谢你,我也不得不改变: -
,{ 持续时间:300 }
简单地说: -
,300
然后回调工作:-)这是最终的代码(在我做出其他更改之前): -
// 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 :(得分:0)
在您的代码中修复这些:
}, {
duration: 300
}), //--> REMOVE THIS parens
function () {
$('.click-here').remove();
}; //ADD A PARENS HERE, like });
由于您错误地将第三个参数传递给animate()
,这是回调函数。做出上述变化并尝试。
这将是更正后的版本:
// 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() {
});