当我单击“新建”按钮时,开始 jQuery 操作:
1.)创建DIV并将Class“块”添加到DIV
2.) 附加到“.container”
3.) 将容器中的此 DIV 从不透明度 0 设置为 1
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');
});