[英]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.