Hello, I apologize immediately for a stupid question, but for a long time I really can’t give a condition to scroll on the popup window. In general, popup opens, trying to give a condition on the scroll:

$('#popup_blok').scroll(function(){ alert('ok'); }); 

but does not work, tried this:

 $('#popup_block').live('scroll', function(){ alert('ok'); }); 

also does not work, generally 0 reactions.

popup_block block is loaded from the database via Ajax. The fade block is created when the user clicks and is added to the dom element after the wrapper:

 <div id="wrapper"></div> <div id="fade"> <div id="left"></div> <div id="right"></div> <div id="popup_block"> <div id="popup_conteiner"> <!-- Загруженные элементы из БД --> </div> </div> </div> 

I tried the sample in different ways: $ ('# popup_block'), $ ('# fade #popup_block'), $ ('# popup_conteiner'), etc. Can I somehow give a condition on the popup window on the scroll?

The thing is, I need to know the height of #popup_conteiner, and assign its height to #left and #right. I tried to assign it immediately in Ajax

 success: function(html){ //////////////////// $('#right, #left').height($('#popup_conteiner').outerHeight(true)); }); 

So it gives not the exact height, but if you close the pop-up window and again open the exact height it gives, but I need the exact height right away. Tried and height () is also not the result.

And now I decided to try to give a condition when scrolling to assign

 $('#popup_block').live('scroll', function(){ $('#right, #left').height($('#popup_conteiner').outerHeight(true)); }); 

but the result is zero.

Give some advice.

  • one
    live is outdated and no longer works in new versions (from 1.9 it seems) use 'on' - zb '11
  • hey, do you add ajax with id? aren't there several such blocks as a result? - zb '
  • Yes, a div with id is added when you click using jquery, then I load more elements from the database - bemulima

1 answer 1

The scroll event cannot be hung on a dynamic element through the live() method and others like it.

I will recommend this:

 $('#block').on('mouseenter', '.element', function() { if($(this).data('scroll') == undefined) { $(this).data('scroll', true); $(this).scroll(function(){ //... }); } }); 
  • I like your code, but it doesn't help me - bemulima
  • @bemulima code is fully working jsfiddle.net/q7dxu - lampa
  • Well, yes, cool, even the simplest doesn't work for me $ ('# fade'). on ('scroll', function () {alert ('ok');}); - bemulima
  • @bemulima if your window does not contain a scroll, then the script will not work. - lampa
  • I have a scoll - bemulima