I have a textarea in a form that users frequently use. When a user manually adjusts the size of the textarea using the resize thing in the bottom-right corner of the textarea, I save the height to localStorage. I want to set the textarea height to the height saved in localStorage but when I do the textarea can't be resized smaller than the height that was set.
It works fine in Firefox but not in Chrome.
I'm currently setting the height using jQuery's .height(). I've also tried .outerHeight(), .css(), .style, .setProperty(). None worked.
Code I'm working with:
id = params.id ? params.id : $el.attr('id');
lsHeight = localStorage.getItem('textareaOuterHeight-' + id);
if (lsHeight != null) {
$el.height(lsHeight);
}
$el.data('defaultOuterHeight', $el.outerHeight());
$el.on('click', function() {
if ($el.data('defaultOuterHeight') !== $el.outerHeight()) {
localStorage.setItem('textareaOuterHeight-' + id, $el.outerHeight());
}
});
-
Can you provide some code you use?Iurii Drozdov– Iurii Drozdov2017年01月09日 12:48:12 +00:00Commented Jan 9, 2017 at 12:48
-
@IuriiDrozdov Code added.NeedsHelp– NeedsHelp2017年01月09日 15:04:49 +00:00Commented Jan 9, 2017 at 15:04
-
Please take a look jsfiddle.net/pL4shps0Iurii Drozdov– Iurii Drozdov2017年01月09日 15:17:44 +00:00Commented Jan 9, 2017 at 15:17
-
I tried the jsfiddle and it's behaving the way I described. I can't resize the textarea to a size smaller than the height set.NeedsHelp– NeedsHelp2017年01月09日 15:32:14 +00:00Commented Jan 9, 2017 at 15:32
-
Also, my problem is that it doesn't work on Chrome.NeedsHelp– NeedsHelp2017年01月09日 15:34:18 +00:00Commented Jan 9, 2017 at 15:34
2 Answers 2
It seems to work correctly for me:
$('textarea').height(20);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<textarea name="" id="" cols="50" rows="50"></textarea>
Instead of saving+modifying the height of the textarea with the height CSS value, you could try to modify the number of columns or rows:
$('textarea').attr('rows',60);
2 Comments
It is a Chrome bug which is still open https://bugs.chromium.org/p/chromium/issues/detail?id=94583
You can use workaround from here jsfiddle.net/nz8ut/2/
And you can take a look at this question Custom CSS to allow chrome textarea resize smaller than initial state?
Comments
Explore related questions
See similar questions with these tags.