简体   繁体   English

当屏幕尺寸小于480px时,如何禁用jQuery功能?

[英]How do I disable jQuery function when screen size is less than 480px?

i have an upload form that is fixed to the top and follows with my scrolling. 我有一个固定在顶部的上传表单,然后进行滚动。 Now I want to disable this function when it's viewed on a phone. 现在,我想在手机上查看该功能时将其禁用。

Here is my script code. 这是我的脚本代码。

$(window).scroll(function () {
    if ($(window).scrollTop() > 430 && $(window).width() > 480) {
        $('#formwrap').addClass('fixed');
    } else {
        $('#formwrap').removeClass('fixed');
    }
});

use .resize() instead: 使用.resize()代替:

$(window).resize(function () {

    ............

}).resize(); //<----this will be fired when dom gets ready.

See .scroll() event looks for scroll but in your case you have to use .resize() because you want to enable/disable some function on basis of screen size and don't forget to trigger that as i mentioned in the answer or you can do. 请参阅.scroll()事件寻找滚动,但是在您的情况下,您必须使用.resize()因为您要基于屏幕大小启用/禁用某些功能,并且不要忘记像我在答案中提到的那样触发它或你可以做。

$(window).resize(); // or
$(window).trigger('resize');

You need $(window) .resize() 您需要$(window) .resize()

$(window).resize(function () {.. });

Read Cross-browser window resize event - JavaScript / jQuery 读取跨浏览器窗口调整大小事件-JavaScript / jQuery

In Jquery 在jQuery中

$(window).resize(function () {

//Your function

.. }).resize();;

In CSS 在CSS中

@media only screen and (max-width: 400px) {

    #formwrap{display:none;}

}

try this code : 试试这个代码:

if(screen.width>=480)
{
    $('#formwrap').addClass('fixed');
} else {
    $('#formwrap').removeClass('fixed');
}

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

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