gpt4 book ai didi

jQuery追加DIV然后动画

转载 作者:行者123 更新时间:2023-12-01 00:07:47 25 4
gpt4 key购买 nike

当我点击“new”按钮时,启动 jQuery 操作:

1.) 创建 DIV 并将Class“ block ”添加到 DIV

2.) 附加到“.container”

3.) 在容器中设置此 DIV 的不透明度从 0 到 1 的动画

JsFiddle Example

HTML

<div class="panel">
<button class='new'> + </button>
</div>
<div class="container">
</div>

CSS

.block {
margin: 0px;
width: 200px;
display: inline-block;
border-right:thin dashed #aaa;
opacity: 0;
}
.panel {
position: absolute;
top: 100px;
padding: 5px;
color: #FFF;
font-size: 15px;
background: #d30;
height: 30px;
cursor:pointer;
}
.container {
position: absolute;
top: 145px;
left: 0px;
}
button{
font-size: 20px;
padding: 0px;
}

jQuery

function createChatBox(title) {
$(" <div />" ).attr("id","block_"+title)
.addClass("block")
.html('<div class="title">text1 '+title+'</div>')
.appendTo($( ".container" , {
css: {
display: 'inline-block',
opacity: 0
}
}).animate({ opacity: 1 }) );
}

$(".new").click(function(){
createChatBox('text2');
});

最佳答案

您需要将appendTo部分更改为:

    .appendTo(".container" , {
css: {
display: 'inline-block',
opacity: 0
}
}).animate({ opacity: 1 });

关于jQuery追加DIV然后动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10282709/

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