javascript - How to check bottom of child div touching parent bottom -


i'm trying change position of child element(with varying height based on text) using range input,i stop applying top position once child div touches bottom of parent having fixed height.

$('#change_position').on('input', function () {     var val = +$(this).val(),         scrsize = parseint($('.screen').css('height')),          stop = $('.screentip').offset().top,          h = parseint($('.screentip').css('height')),          tofsset = stop - h;      if (tofsset < scrsize) {         $('.screentip').css('top', val + "%");     } }); 

the height expecting jquery return string ending "px". can use function .height(). return height of element integer. have tried modiefied version of code:

$('#input').on('input', function () {     var val = parseint($(this).val()),         scrsize = parseint($('#container').height()),         txtsize = parseint($("#text").height()),          stop = scrsize - txtsize,         valinpixel = scrsize * val / 100;      if (valinpixel < stop) {         $('#text').css('top', val + "%");     }     else     {       $("#text").css("top", stop + "px");     } }); 

the else part position element bottom, if number exceeds frame. may have aware of padding , margin. lead mispositioning.

hope helps.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -