Placeholder attribute on text input with iOS 6 from landscape to portrait

南笙酒味 提交于 2019-12-21 11:29:49

问题


I have a problem after updating to iOS 6 that is driving me nuts.

It looks like any time I have the attribute "placeholder" on an input field, while rotating from Portrait to Landscape and back to Portrait again the page shifts some pixels on the left side causing a horizontal bar.

I concluded after long research that it has to be something related to the meta viewport because every time I use the content="width=device-width" all works fine.

P.S Yes I really need to have a percent width on the input so as to have liquid design:)

Here is the example to recreate the issue. Thanks...

<html>
<head>
    <title>test</title>
    <meta content="width=device-width, initial-scale=1, maximum-scale=1" name="viewport"/>
</head>
<body>

    <div style="width:100%;background-color:red">
        <input id="testInput"  placeholder="test" style="width:90%;" />
    </div>
</body>
</html>

回答1:


I found this problem. and fix it.

(URL : http://mooki83.tistory.com/2656550 (in korean))

testURL : http://mooki83.da.to/m/testios6.html

javascript :

/* Optimized PLACEHOLDER for iOS6 - Mooki ( http://mooki83.tistory.com ) */


$(document).ready(function(){
    $(window).bind("orientationchange.fm_optimizeInput", fm_optimizeInput);
});

function fm_optimizeInput(){
    $("input[placeholder],textarea[placeholder]").each(function(){
        var tmpText = $(this).attr("placeholder");
        if ( tmpText != "" ) {
            $(this).attr("placeholder", "").attr("placeholder", tmpText);
        }
    })
}



回答2:


Applying "overflow: hidden;" on the containing element solved this issue for me.




回答3:


CSS fix:

body>div {
    overflow-y: auto;
}



回答4:


Non js answer

Add overflow:hidden to parent element and it will work like a charm



来源:https://stackoverflow.com/questions/12582788/placeholder-attribute-on-text-input-with-ios-6-from-landscape-to-portrait

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!