원생 js와 jq 복귀

1456 단어 끝!
<script type="text/javascript">

$(function(){

		showScroll();

		function showScroll(){

			$(window).scroll( function() { 

				var scrollValue=$(window).scrollTop();

				scrollValue > 100 ? $('div[class=scroll]').fadeIn():$('div[class=scroll]').fadeOut();

			} );	

			$('#gotop').click(function(){

				$("html,body").animate({scrollTop:0},200);	

			});	

		}

	});

</script>


원생 js 구현:
 webkit :document.documentElement.scrollTop||document.body.scrollTop;
<script type="text/javascript">

function goTopEx(){

        var obj=document.getElementById("gotop");

        function getScrollTop(){

                return document.documentElement.scrollTop||document.body.scrollTop;

            }

        function setScrollTop(value){

                document.documentElement.scrollTop=value;

				document.body.scrollTop=value;

            }    

        window.onscroll=function(){getScrollTop()>0?obj.style.display="":obj.style.display="none";}

        obj.onclick=function(){

            var goTop=setInterval(scrollMove,10);

            function scrollMove(){

                    setScrollTop(getScrollTop()/1.1);

                    if(getScrollTop()<1)clearInterval(goTop);

                }

        }

    }

goTopEx();

</script>


  

좋은 웹페이지 즐겨찾기