我有下一个javascript代码:
function() {
$( this ).on( "resize", $special.handler);
}
它工作正常,但我不需要这个来触发高度变化,我需要只在一个变化上工作。
因此,我尝试在调整大小检测中添加if语句,并仅在宽度更改时绑定$special.handler
。
找不到一种简单的方法可以做到这一点,所以你能帮我找到我做错的事吗?
目前我已经完成了下一个代码
function() {
var widthBefore = $(this).width();
$( this ).on( "resize", function() {
if ($(this).width() != widthBefore) {
$(this).on( WIDTH CHANGE ONLY, $special.handler);
widthBefore = $(this).width();
}
});
}
答案 0 :(得分:0)
没有宽度更改事件,但如果必须维护上下文,则可以使用 -
function() {
var widthBefore = $(this).width();
$( this ).on( "resize", function() {
if ($(this).width() != widthBefore) {
$.proxy($special.handler,this);
widthBefore = $(this).width();
}
});
}