且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

《单页web应用 javaScript从前端到后端》 1.2 spa.html小例子demo

更新时间:2022-02-09 11:35:56

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            body{
                width: 100%;
                height: 100%;
                overflow: hidden;
                background-color: #777;
            }
            #spa{
                position: absolute;
                top: 8px;
                left: 8px;
                bottom:8px;
                right: 8px;
                border-radius: 8px 8px 0 8px;
                background-color: #ffffff;
            }
            .spa-slider{
                position: absolute;
                bottom: 0;
                right: 2px;
                width: 300px;
                height: 16px;
                border-radius: 8px 0 0 0;
                background-color: #f00;
            }
        </style>
        <script src="scripts/jquery.js"></script>
        <script>
            var spa = (function($){
                var configMap = { 
                    extended_height:434,
                    extended_title:'clcik to retract',
                    retracted_height:16,
                    retracted_title:'click to extend',
                    template_html:'<div class="spa-slider"><\/div>'
                },
                $chatSlider,
                toggelSlider,onClickSlider,initModule;
                toggelSlider = function(){
                    var slider_height = $chatSlider.height();
                    if(slider_height === configMap.retracted_height){
                        $chatSlider
                        .animate({height:configMap.extended_height})
                        .attr("title",configMap.extended_title);
                        return true;  
                    }else if(slider_height === configMap.extended_height){
                        $chatSlider
                        .animate({height:configMap.retracted_height})
                        .attr("title",configMap.retracted_title);
                        return true;
                    }
                    return false;
                };
                onClickSlider = function(event){
                    toggelSlider();
                    return false;
                };
                initModule = function($container){
                    $container.html(configMap.template_html);
                    $chatSlider = $container.find('.spa-slider');
                    $chatSlider.attr('title',configMap.retracted_title)
                    .click(onClickSlider);
                     
                    return true;
                };
                return {initModule:initModule};
            }(jQuery));
             
            $(function(){
                    spa.initModule(jQuery('#spa'));
            })
        </script>
 
    </head>
    <body>
        <div id="spa">
        </div>
    </body>
</html>


本文转自  小旭依然  51CTO博客,原文链接:http://blog.51cto.com/xuyran/1890478