[jquery] 윈도우 이벤트

개발 Programming/JQUERY|2018. 9. 4. 15:46

ready 문서 객체가 준비를 완료함

load 윈도우(문서 객체)를 불러들일때 발생함

unload 윈도우(문서객체)를 닫을 때 발생함

resize 윈도우의 크기를 변화시킬때 발생함

scroll 윈도우를 스크롤할 때 발생함

error 에러가 있을 때 발생함


무한 스크롤

<html>
<head>
        <style>
        </style>
<script src='https://code.jquery.com/jquery-3.3.1.js'></script>
<script>
$(document).ready(function(){
                    $(window).scroll(function(){
                        var scrollHeight = $(window).scrollTop() + $(window).height();
                        var documentHeight = $(document).height();

                        if(scrollHeight+200 >= documentHeight){
                            for(var i =0; i< 10; i++){
                                $('<h3>Infinity Scroll</h3>').appendTo('body');
                            }
                        }
                    });
});
                //테스트를 위해 내부에 공간을 채둠
                $(document).ready(function(){
                    for(var i=0; i<20 ; i++){
                        $('<h3>Infinity Scroll</h3>').appendTo('body');
                    }
                });
</script>
</head>
<body>
        
</body>
</html>


댓글()