jquery移动设备方向更改不调整文本区域的大小

时间:2012-02-02 16:03:26

标签: javascript jquery css jquery-mobile

我正试图找出一种在设备旋转时使用JQM调整文本区域大小的方法。基本上,我有一个文本区域在加载时看起来很好,无论是纵向还是横向,但是当设备旋转时,它不会调整大小。以下是代码的一些内容:

.message-entry{
   margin-left:10px;
   margin-right:0;
   margin-bottom:-20px;
}

和HTML:

 <footer data-role="footer" id="footer" data-theme="b" data-position="fixed">               
            <label class="label-message-entry" for="chatMessageEntry">Enter a message:</label>
            <textarea rows="8" name="textarea" class="message-entry" id="chatMessageEntry"></textarea>
            <a id="chatReplyButton" class="reply-button" data-role="button" data-icon="plus">Reply</a>              
        </footer> <!--end footer--> 

然后是orientationchange事件:

$(window).bind( 'orientationchange', function(e){
        var newWidth = $(window).width();
        $('.message-entry').css({'width':newWidth + 'px'});     
});

任何想法?谢谢!

1 个答案:

答案 0 :(得分:0)

您是否尝试过在媒体查询中为textarea提供最小宽度?

@media all and (max-width: 480px) and (min-width: 321px){
    .message-entry{
        min-width:470px;
    }
}
@media all and (max-width: 320px){
    .message-entry{
        min-width:310px;
    }
}