๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ–ฅ๏ธํ”„๋ก ํŠธ์—”๋“œ/HTML | CSS | JAVASCRIPT

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ - alertBox

by Janger 2022. 4. 10.
728x90
๋ฐ˜์‘ํ˜•

 

 

function alertBox(msg, delay = 3000){

        var container = document.createElement('div');
        container.setAttribute('class', 'alertBox-container');

        container.style.width = '100%';
        container.style.height = '100px';
        container.style.position = 'fixed';
        container.style.bottom = '0';
        container.style.display = 'flex';
        container.style.justifyContent = 'center';


        var box = document.createElement('div');

        box.style.width = '350px';
        box.style.height = '100px';
        box.style.borderRadius = '15px 15px 0 0';
        box.style.backgroundColor = 'rgb(254, 253, 255)';
        box.style.boxShadow = '1.5px 1px 10px rgba(0, 0, 0, 0.9)'
        box.style.display = 'flex';
        box.style.justifyContent = 'center';
        box.style.alignItems = 'center';
        box.style.marginTop = '200px';

        box.style.transition = '.5s';
        
        var message = document.createElement('p');

        message.innerHTML = msg;
        message.style.fontSize = '23px';
        message.style.userSelect = 'none';


        box.appendChild( message );

        container.appendChild( box );

        document.body.appendChild( container );

        // // ๋“ฑ์žฅ
        setTimeout( ()=>{
            box.style.marginTop = '0';
        }, 0 )        
        
        // ์‚ฌ๋ผ์ง
        setTimeout( ()=>{
            box.style.marginTop = '200px';
            setTimeout( ()=>{ container.remove() }, 1000 )
        }, delay )

    }

    alertBox('๋งŒ๋‚˜์„œ ๋ฐ˜๊ฐ‘์Šต๋‹ˆ๋‹ค!', 5000);

 

728x90
๋ฐ˜์‘ํ˜•