jQuery check if browser support position: fixed

后端 未结 7 620
灰色年华
灰色年华 2021-01-04 09:13

How do I check if browser supports position:fixed using jQuery. I assume I have to use $.support I think, but how?

Thank you for your time.

相关标签:
7条回答
  • 2021-01-04 10:03

    You could check if position exists by making a code like this:

    <html>
    <script type="text/javascript">
    test = function() {
    if(!!document.getElementById("test").style.position) {
    alert('true');
    }
    else{
    alert('false');
    }
    }
    </script>
    
    <body>
    <p id="test" onclick="test();" style="position:fixed;">Hi</p>
    </body>
    </html>
    

    Since position exists in all main browser this will always return true. I imagine there isn't a way to check the possible values of position, so you'll have to check which browser and which version the user are viewing your page as Paolo Bergantino said.

    0 讨论(0)
提交回复
热议问题