[英]How to use jquery resize run funtion one time?
I want to use run 2 functions jquery when resize window. 我想在调整窗口大小时使用run 2函数jquery。 But I just want to do they one time. 但是我只想做一次。 code can be like: 代码可以像这样:
jQuery(document).ready(function () {
var screenwidth=jQuery(window).width();
if(screenwidth>991){
dofunction1();
}
else{
dofunction2();
}
});
I want when screenwidth>991 do dofunction1() 1 time, and when screenwidth<=991 do dofunction2() 1 time. 我想要screenwidth> 991做dofunction1()1次,而screenwidth <= 991做dofunction2()1次。 Hope your help!! 希望你的帮助!
You can use .one()
to bind resize
event 您可以使用.one()
绑定resize
事件
Attach a handler to an event for the elements. 将处理程序附加到元素的事件。 The handler is executed at most once per element per event type. 每个事件类型的每个元素最多只能执行一次处理程序。
$(window).one('resize', function () {
var screenwidth = jQuery(window).width();
if (screenwidth > 991) {
dofunction1();
} else {
dofunction2();
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.