要求點擊圖片出現(xiàn)彈窗 彈窗出現(xiàn)的時候,根據(jù)圖片高 > 屏幕高,來判斷是否阻止底層滾動,現(xiàn)在問題是,當我第一次點擊出現(xiàn)彈出層時候,圖片高度可以獲取到?判斷也沒問題?但是當我點擊一個長圖的時候,執(zhí)行touchmove事件時候,圖片高度出現(xiàn)了2種分別為第一次的彈窗圖片240 跟最新的圖片高度,我是在這里 執(zhí)行完彈出層后執(zhí)行回調(diào)函數(shù)getPopImgHeight,?我就不明白為什么再點擊的時候回有上次的變量 ,而且 應該再出現(xiàn)彈出層的時候 不應該重新獲取img的高度 吧上一個覆蓋了嗎?求大神幫忙解答下。。謝謝<div?id="popup-box">????<div?id="popclose"></div>????<div?class="imgbox"?id="imgbox">????????<img?src="">????</div>????<div?class="h6box?in"></div></div>var?popBox?=?$('#popup-box'),????popImg?=?popBox.find('img'),????popText?=?popBox.find('.h6box');var?screenH?=?$(window).height();function?getPopImgHeight()?{????var?imgHeight?=?popImg.height();????console.log('原來的'+imgHeight);????$('#imgbox').on('touchstart',?function()?{????????popText.attr('class',?'h6box?out');????});????$('#imgbox').on('touchmove',?function()?{????????console.log('imgHeight:'?+?imgHeight);????????console.log(imgHeight?<?screenH);????????if?(imgHeight?<?screenH)?{?//?阻止?jié)L動?????????????console.log('1')?????????????//?return?false;????????}?else?{?//?允許滾動?????????????console.log('2')?????????????//?return?true;????????}????});}$('.baoImgQ').on('click',?'a',?function()?{????stopDefault();????var?imgLen?=?$(this).find('img').length;????if?(imgLen?>?0)?{????????var?imgSrc?=?getRealSrc($(this).attr('href'));????????var?hText?=?$(this).parent().next().next('h6').text();????????console.log(imgSrc?+?';'?+?hText);????????addPopContent(imgSrc,?hText);????????popBox.fadeIn('fast',?getPopImgHeight);????}});//?關閉時候重置$('#popclose').on('click',?function()?{????popBox.fadeOut('fast');????popImg.attr('src',?'');????popText.text('').attr('class',?'h6box?in').show();});function getPopImgHeight() {? ? var imgHeight = popImg.height();? ? console.log('原來的'+imgHeight);? ? $('#imgbox').on('touchstart', function() {? ? ? ? popText.attr('class', 'h6box out');? ? });? ? $('#imgbox').on('touchmove', function() {? ? ? ? console.log('imgHeight:' + imgHeight);? ? ? ? console.log(imgHeight < screenH);? ? ? ? if (imgHeight < screenH) { // 阻止?jié)L動? ? ? ? ? ? ?console.log('1')? ? ? ? ? ? ?// return false;? ? ? ? } else { // 允許滾動? ? ? ? ? ? ?console.log('2')? ? ? ? ? ? ?// return true;? ? ? ? }? ? });}$('.baoImgQ').on('click', 'a', function() {? ? stopDefault();? ? var imgLen = $(this).find('img').length;? ? if (imgLen > 0) {? ? ? ? var imgSrc = getRealSrc($(this).attr('href'));? ? ? ? var hText = $(this).parent().next().next('h6').text();? ? ? ? console.log(imgSrc + ';' + hText);? ? ? ? addPopContent(imgSrc, hText);? ? ? ? popBox.fadeIn('fast', getPopImgHeight);? ? }});
閉包的問題中執(zhí)行touchmove事件的問題
wubin_work
2019-05-28 11:12:28