gpt4 book ai didi

javascript - jQuery 过早地向元素添加 css 属性

转载 作者:太空宇宙 更新时间:2023-11-04 04:16:42 25 4
gpt4 key购买 nike

我试图让页面上的一个元素在鼠标离开时淡出,然后对其应用一些 css 属性。问题是 css 属性在元素完全淡出之前被添加到元素中。这是我尝试过的:

$(".tiptrigger").mouseleave(function() { 
var s_id = $(this).attr('id');

$("#tiptip_holder-"+s_id).fadeOut("fast");

$("#tiptip_holder-"+s_id).css({"margin-left": "0px", "margin-top": "0px"});

});

当那行不通时,我尝试了:

$(".tiptrigger").mouseleave(function() { 
var s_id = $(this).attr('id');

$("#tiptip_holder-"+s_id).fadeOut("fast").delay(500).css({"margin-left": "0px", "margin-top": "0px"});

});

当这不起作用时,我终于尝试了:

$(".tiptrigger").mouseleave(function() { 
var s_id = $(this).attr('id');
$("#tiptip_holder-"+s_id).fadeOut("fast");

}, function() {
$("#tiptip_holder-"+s_id).css({"margin-left": "0px", "margin-top": "0px"});

});

有什么建议吗?

最佳答案

您可以使用 callback function这里像:

$("#tiptip_holder-" + s_id).fadeOut("fast", function () {
$(this).css({
"margin-left": "0px",
"margin-top": "0px"
});
});

关于javascript - jQuery 过早地向元素添加 css 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19811350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com