Reputation: 1327
When I clik on the button "new" start jQuery action:
1.) create DIV and addClass "block" to the DIV
2.) appendTo ".container"
3.) animate this DIV in container from opacity 0 to 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');
});
Upvotes: 4
Views: 3266
Reputation: 20415
Is this what you are looking for:
function createChatBox(title) {
$(" <div />" )
.attr("id","block_"+title)
.addClass("block")
.html('<div class="title">text1 '+title+'</div>')
.css({
display: 'inline-block',
opacity: 0
})
.appendTo($( ".container" ))
.animate({ opacity: 1 });
}
Upvotes: 2
Reputation: 3141
You need to change your appendTo section to this:
.appendTo(".container" , {
css: {
display: 'inline-block',
opacity: 0
}
}).animate({ opacity: 1 });
Upvotes: 3
Reputation: 757
You code seems to be broken, some mismatch parenthesis / {}. Here is a fix, it is what you want ? http://jsfiddle.net/mamadrood/bckHD/1/
Upvotes: 1