简体   繁体   English

Javascript 尺寸屏幕小于 60% 可见时隐藏 div(显示移动键盘时)

[英]Javascript hide div when size screen is less than 60% visible (when mobile keyboard is displayed)

I'm trying to hide a div when user fills a form on a mobile device, so the screen could be more visible due to keyboard displaying.当用户在移动设备上填写表单时,我试图隐藏一个 div,因此由于键盘显示,屏幕可能更加明显。

HTML HTML

<div id="fixed-bottom-menu">BLA BLA BLA</div>

The JS code must display again the div when mobile keyboard is hidden.隐藏移动键盘时,JS代码必须再次显示div。

My attempt:我的尝试:

<script type="text/javascript">
    if( $(window).width() < 60%)
    {
        document.write( '<style>"#fixed-bottom-menu"{visibility:hidden}</style>' );
    }
</script>

you need a eventlistner to do this and the % should not be there and you need to check the current viewport height is 40% less than the total screen size inorder to make it work您需要一个 eventlistner 来执行此操作,并且 % 不应该在那里,您需要检查当前视口高度是否比总屏幕尺寸小 40% 才能使其正常工作

if you are using document.write() it will remove jquery from the script it is not advisable to using document.write()如果您使用的是 document.write() 它将从脚本中删除 jquery 不建议使用 document.write()

check this https://jsfiddle.net/anirudhsanthosh/hrsd8o5p检查这个https://jsfiddle.net/anirudhsanthosh/hrsd8o5p

use jquery.css() method to change css property of an element使用 jquery.css() 方法更改元素的 css 属性

<script type="text/javascript">
        $(window).resize(()=>{

         if(( window.innerHeight/screen.availHeight)*100 < 60)
         {
         
            $('#fixed-bottom-menu').css({display:"none"})
            return
         }
         $('#fixed-bottom-menu').css({display:"block"})
    })
    
    </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM