JavaScript+html 전단 페이지 슬라이딩 검증 실현(2)

본 논문 의 사례 는 멋 진 전단 페이지 미끄럼 검증 의 구체 적 인 코드 를 공유 하여 여러분 께 참고 하 시기 바 랍 니 다.구체 적 인 내용 은 다음 과 같 습 니 다.
멋 진 전단 페이지 슬라이딩 인증 공유
앞 에 이미 보 냈 습 니 다일종여기 하나 더 보 내 주세요.다만 필터 가 다 릅 니 다.
아니면 코드 를 직접 올 릴 까요?

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <style>
        /*       ,     */
        #dragContainer {
            position: relative;
            display: inline-block;
            background: #e8e8e8;
            width: 300px;
            height: 33px;
            border: 2px solid #e8e8e8;
        }
        /*       ,     */
        #dragBg {
            position: absolute;
            background-color: #7ac23c;
            width: 0px;
            height: 100%;
        }
        /*          */
        #dragText {
            position: absolute;
            width: 100%;
            height: 100%;
            /*        */
            text-align: center;
            /*       ,        ,          line-height ,  div   */
            line-height: 33px;
            /*         */
            user-select: none;
            -webkit-user-select: none;
        }
        /*    */
        #dragHandler {
            position: absolute;
            width: 40px;
            height: 100%;
            cursor: move;
        }
        /*        */
        .dragHandlerBg {
            background: #fff no-repeat center url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA3hpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNS1jMDIxIDc5LjE1NTc3MiwgMjAxNC8wMS8xMy0xOTo0NDowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyL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gqEAcTkmNCU6AL9d8WII4HOvk3ITkWJAXWUMlOoGQHmsE45ViQ2KuBuASoYC4Wf+OUYxz6mQkgwAAN9mIrUReCXgAAAABJRU5ErkJggg==");
        }
        /*             √*/
        .dragHandlerOkBg {
            background: #fff no-repeat center url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA3hpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNS1jMDIxIDc5LjE1NTc3MiwgMjAxNC8wMS8xMy0xOTo0NDowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo0ZDhlNWY5My05NmI0LTRlNWQtOGFjYi03ZTY4OGYyMTU2ZTYiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NDlBRDI3NjVGMkQ2MTFFNEI5NDBCMjQ2M0ExMDQ1OUYiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6NDlBRDI3NjRGMkQ2MTFFNEI5NDBCMjQ2M0ExMDQ1OUYiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENDIDIwMTQgKE1hY2ludG9zaCkiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDphNWEzMWNhMC1hYmViLTQxNWEtYTEwZS04Y2U5NzRlN2Q4YTEiIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6NGQ4ZTVmOTMtOTZiNC00ZTVkLThhY2ItN2U2ODhmMjE1NmU2Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+k+sHwwAAASZJREFUeNpi/P//PwMyKD8uZw+kUoDYEYgloMIvgHg/EM/ptHx0EFk9I8wAoEZ+IDUPiIMY8IN1QJwENOgj3ACo5gNAbMBAHLgAxA4gQ5igAnNJ0MwAVTsX7IKyY7L2UNuJAf+AmAmJ78AEDTBiwGYg5gbifCSxFCZoaBMCy4A4GOjnH0D6DpK4IxNSVIHAfSDOAeLraJrjgJp/AwPbHMhejiQnwYRmUzNQ4VQgDQqXK0ia/0I17wJiPmQNTNBEAgMlQIWiQA2vgWw7QppBekGxsAjIiEUSBNnsBDWEAY9mEFgMMgBk00E0iZtA7AHEctDQ58MRuA6wlLgGFMoMpIG1QFeGwAIxGZo8GUhIysmwQGSAZgwHaEZhICIzOaBkJkqyM0CAAQDGx279Jf50AAAAAABJRU5ErkJggg==");
        }
    </style>
</head>
<body>
        <div id="dragContainer"><!--        -->
            <div id="dragBg"></div><!--      -->
            <div id="dragText"></div><!--        -->
            <div id="dragHandler" class="dragHandlerBg"></div>
        </div> <!--                      -->
</body>

<script>
    //  (             )
    window.onload = function() {
        //        ,    
        var dragContainer = document.getElementById("dragContainer");
        //        ,    
        var dragBg = document.getElementById("dragBg");
        //          
        var dragText = document.getElementById("dragText");
        //    
        var dragHandler = document.getElementById("dragHandler");

        //                         =                                 -          
        var maxHandlerOffset = dragContainer.clientWidth - dragHandler.clientWidth;
        //         
        var isVertifySucc = false;

        initDrag();

        function initDrag() {
            //           “      ”
            dragText.textContent = "      ";
            //           
            dragHandler.addEventListener("mousedown", onDragHandlerMouseDown);
        }

        //    
        function onDragHandlerMouseDown() {
            //      
            document.addEventListener("mousemove", onDragHandlerMouseMove);
            //      
            document.addEventListener("mouseup",  onDragHandlerMouseUp);
        }

        //    
        function onDragHandlerMouseMove() {
            /*
            html     width  ,  clientWidth
            offsetX        ,clientX pageX        
            */
            //     
            var left = event.clientX - dragHandler.clientWidth / 2;
            //
            if(left < 0) {
                left = 0;
                //          >          ,         
            } else if(left > maxHandlerOffset) {
                left = maxHandlerOffset;
                verifySucc();
            }
            //     
            dragHandler.style.left = left + "px";
            //       
            dragBg.style.width = dragHandler.style.left;
        }

        //      
        function onDragHandlerMouseUp() {
            //        
            document.removeEventListener("mousemove", onDragHandlerMouseMove);
            //        
            document.removeEventListener("mouseup", onDragHandlerMouseUp);
            //        
            dragHandler.style.left = 0;
            //       
            dragBg.style.width = 0;
        }

        //    
        function verifySucc() {
            //    ,    
            isVertifySucc = false;
            //           “    ”  
            dragText.textContent = "    ";
            dragText.style.color = "white";
            //         
            dragHandler.setAttribute("class", "dragHandlerOkBg");
            //        
            dragHandler.removeEventListener("mousedown", onDragHandlerMouseDown);
            //         
            document.removeEventListener("mousemove", onDragHandlerMouseMove);
            //        
            document.removeEventListener("mouseup", onDragHandlerMouseUp);
            //                
            //window.location.href="    .html" rel="external nofollow" ;
        };
    }
</script>
</html>
효 과 는 다음 과 같다.



이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기