Skip to content

Instantly share code, notes, and snippets.

@beakr
Created March 30, 2012 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beakr/2251323 to your computer and use it in GitHub Desktop.
Save beakr/2251323 to your computer and use it in GitHub Desktop.
Expanding nice comment box.
.comment_box {
/* Cosmetic */
margin-left: 30px;
margin-top: 50px;
border-radius: 7px;
border-color: #BABABA;
box-shadow: 1px 5px 2px #EDEDED;
height: 130px;
width: 300px; /* Was 470px */
/* Text */
font-family: "Helvetica Neue", sans-serif;
font-size: 15px;
font-weight: normal;
color: #7A7A7A;
padding: 10px;
}
.comment_box:focus {
outline: none;
border-color: #7AB0E6
}
<html>
<body>
<textarea class="comment_box">Post a comment...</textarea>
</body>
</html>​
// Auto-selection when clicked
$(".comment_box").click(function() {
$(".comment_box").css('color', 'black');
});
// Text turns gray again when not typing
$(".comment_box").blur(function() {
$(".comment_box").css('color', '#7A7A7A');
});
// Post a comment... dissapears when field is clicked
$('.comment_box').focus(function() {
if ($(this).val() === 'Post a comment...') {
return $(this).val('');
}
});
// Post a comment... reappears when field is not in focus anymore
$('.comment_box').blur(function() {
if ($(this).val() === '') {
return $(this).val('Post a comment...');
}
});
// Expanding
$(".comment_box").focus(function() {
$(this).animate({ width: "470px" }, 250);
$(this).animate({ height: "200px" }, 250);
});
$(".comment_box").blur(function() {
$(this).animate({ width: "300px" }, 200);
$(this).animate({ height: "130px" }, 200);
});​
@tsundori
Copy link

tsundori commented Sep 9, 2020

asd

@tsundori
Copy link

tsundori commented Sep 9, 2020

qqqqq

@kalumu
Copy link

kalumu commented May 26, 2023

ghj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment