Using jQuery, how do I force a visitor to scroll to the bottom of a textarea to enable the submit button?

前端 未结 5 1978
野的像风
野的像风 2020-12-25 08:50

I have a registration form which contains a read-only textarea. I want to require any visitor to scroll to the bottom of the textarea, which contains terms and conditions or

5条回答
  •  甜味超标
    2020-12-25 08:55

    I recommend this rather, it handles zooming better.

    $('#terms').scroll(function () {
        if ($(this).scrollTop() + $(this).innerHeight() +2 >= $(this)[0].scrollHeight) {
            $('#register').removeAttr('disabled');
        }
    });
    

    The +2 handles a few scaling scenarios when scrolltop+innerheight is marginally below scrollHeight (for some reason I am too lazy to work out).

提交回复
热议问题