gpt4 book ai didi

jquery - 回调内绑定(bind)/取消绑定(bind)

转载 作者:行者123 更新时间:2023-12-01 03:03:12 24 4
gpt4 key购买 nike

我遇到了来自垃圾浏览器的各种各样的问题,我似乎无法用我读过的任何东西来克服这些问题。情况是这样的...我正在使用第三方插件来生成图库。该插件带有图片更改回调,每次更改图像时都会触发该回调。

我想做的是为两个div添加css...一个是包装div,当单击子div时它将滑出,并在再次单击子div时滑回。

这是回调:

        changepicturecallback: function(){
$('.sxpp_commentsImage').unbind(toggle);
oldWidth = $('.pp_pic_holder').width() - 20,
newWidth = $('.pp_pic_holder').width() + (200),
newHeight = $('.pp_hoverContainer').height(),
cImageAlign = newWidth - 20;

var toggle = function() {
if(newWidth == $('.sxpp_comments').width()){
$('.sxpp_comments').animate({width: oldWidth});
}else{
$('.sxpp_comments').animate({width: newWidth});
}
}

$('.sxpp_comments').width(oldWidth).css('background-color','red');
$('.sxpp_commentsImage').css({'float':'right','background-color':'green','width':'20px','height':newHeight});
$('.sxpp_commentsImage').bind('click',toggle);
}

这在 FF4 和 Chrome 中工作得很好...但是,就好像“绑定(bind)”在 Internet Explorer 中没有发生一样。我一直在阅读“.live”和“.delegate”方法,但是(A)我不熟悉它们的工作原理(B)如果可以清除更改中的“.live”,然后添加它回到我正在做的绑定(bind)。

有什么见解或我可能会忽略的事情吗?

编辑***...单击链接时会动态创建 div(显示灯箱)。所以从我读到的所有内容来看……绑定(bind)事件无论如何都是错误的路线。

最佳答案

如果您想在回调中取消绑定(bind)事件函数,只需使用:

$('body').bind('click', function(evt){
console.log('I will be written only once');
$(this).unbind(evt);
})

关于jquery - 回调内绑定(bind)/取消绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6075507/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com