简体   繁体   English

我需要一个jQuery函数才能仅在700px屏幕尺寸以上工作,无法在我的代码中发现错误

[英]I need a jQuery function to only work above 700px screen size, cant spot the error in my code

I have a jquery function that i want to disable below 700px. 我有一个jQuery功能,我想禁用低于700px。 I have the following function: 我有以下功能:

<script>
    $(document).ready(function() {
    $(window).resize();
     });
</script>

and

<script>
    $(window).resize(function() {
        if( $(this).width() > 700 ) {
        $(window).load(function() {
        $('.dh-container').directionalHover();
        });
        }
   });
</script>

This seems like it should work, but i'm a noob to jquery, and can't find the error in my code, and the chrome inspector isn't displaying any errors. 这似乎应该可以工作,但是我对jquery不满意,并且无法在我的代码中找到错误,并且chrome检查器没有显示任何错误。

If someone could spot my error, that would be great. 如果有人能发现我的错误,那将很棒。 And in the future, how would i go about diagnosing a jquery error that the chrome inspector doesn't point out? 将来,我将如何诊断chrome检查器未指出的jquery错误?

Thank you 谢谢

Your code works fine 您的代码工作正常

<script>
    $(document).ready(function() {
        $(window).resize();
    });

    $(window).resize(function() {
        if( $(this).width() > 700 ) {
            $(window).load(function() {
                alert("It's Working above 700px width");
            });
        }
    });
</script>

Always start by testing simple procedures to find out mistakes. 始终从测试简单的程序开始,以找出错误。

Another way: 其他方式:

<script> 
var width = $(window).width();
        if (width > 700) {
            alert('Display Above 700px');
        } else {
            alert('Do nothing since it's under 701px');
        }
</script>

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

相关问题 使用 javascript 时,如何只让我的 header 菜单在屏幕尺寸大于 700 像素时缩小? - How can I only let my header menu shrink when the screen size is larger than 700px by using javascript? 当屏幕宽度&gt; 700像素时隐藏JavaScript吗? - Hide JavaScript when screen width > 700px? 如何使用 Jquery 检查 div 的高度是否大于 700px? - How do I check if the height of a div is greater than 700px, using Jquery? 在屏幕 700 像素 html/css/js 前端 Web 开发后不显示汉堡菜单 - Hamburger Menu not showing after screen 700px html/css/js front-end web dev 如果页面大小小于700px,asp.net重定向到另一个URL - asp.net redirect to another url if page size is less then 700px 使用javascript在700px之后显示div后,如何隐藏它? - after using javascript to show a div after 700px how do i hide it? 将Google Maps InfoWindow设置为超过700像素的宽度 - Set google maps InfoWindow to more than 700px width 我需要帮助使JQuery Function slideDown在我的代码中工作 - I need help getting the JQuery Function slideDown to work in my code 当屏幕尺寸小于480px时,如何禁用jQuery功能? - How do I disable jQuery function when screen size is less than 480px? 当窗口仅在1030px以上时触发函数-并在调整大小或加载时 - Trigger a function when window is only above 1030px - and on Re-size or load
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM