Can Mini Program imitate live rolling comments?

Center

such as the above figure, where the demand is the top comment, there will be a fade-out effect
css3 translate3D can be scrolled, but I don"t know how to achieve the fade-out effect.
ask for advice

Mar.12,2021

opacity attribute and transition attribute can be faded out


the fade-in and fade-out effect should not be an attribute of the on-screen comment itself, but should be covered by a translucent mask on the upper and lower edges

. < hr >

in addition, it may not be appropriate to scroll up and use translate3D, which should be an scroll behavior, because if you want a live broadcast platform like Douyin Kuaishou, you can slide down to watch the historical barrage.

if you use scroll, it seems that you can only use js animation. You can consider implementing a function similar to jquery $('xxx') .animate (scrollTop)

.

this function can consider dividing the scrolling distance into several parts, and then recursively execute it with window.requestAnimationFrame (callback), that is, callback executes scrollTo (one of several parts)

< hr >

the following is an implementation reference for the animate function

/**
 * 
 * @param domEl scrolldom
 * @param top 
 * @param time 
 */
export default function animateScroll(domEl: HTMLElement, distance: number, time: number) {
    if (!window.requestAnimationFrame) {
        window.requestAnimationFrame = function(callback) {
            return setTimeout(callback, 16);
        };
    }
    // step
    var step = function () {
        // 
        const part = distance / time / 16;
        if (Math.abs(part) < 1) {
            domEl.scrollTo(0, distance);
        } else {
            domEl.scrollTo(0, part);
            requestAnimationFrame(step);
        }
    };
    step();
};
Menu