码迷,mamicode.com
首页 > Web开发 > 详细

web单页应用(一)

时间:2017-06-25 12:05:59      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:function   container   ted   应用   overflow   charset   事件   title   setting   

构建第一个单页应用

1.html页面结构

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" type="text/css" href="css/css.css">
    <script src="http://upcdn.b0.upaiyun.com/libs/jquery/jquery-2.0.2.min.js"></script>
    <script type="text/javascript" src=‘js/js.js‘></script>
</head>
<body>
    <div id=‘spa‘></div>
</body>
</html>

 2.css内容

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: #fff;
}
.spa_slider{
    position: absolute;
    bottom: 0;
    right: 2px;
    width: 300px;
    height: 16px;
    cursor: pointer;
    border-radius: 8px 0 0 0;
    background-color:#f00;
}

3.js脚本内容

技术分享
/* Jslint settings */
//module spa
var spa = (function($){
        //模块作用域参数配置
        var configMap = {
            extended_height:200,
            extended_title:"click to retract",
            retracted_height:16,
            retracted_title:‘click to extend‘,
            template_html:"<div class=‘spa_slider‘></div>"
        },$chatSlider,toggleSlider,onClickSlider,initModule;
        //点击切换方法
        toggleSlider = function(){
            var slider_height = $chatSlider.height();
            if( slider_height === configMap.retracted_height ){
                $chatSlider
                .animate({ height : configMap.extended_height },100,"swing")
                .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(evevt){
            toggleSlider();
            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))
View Code

 

4、页面中调用模块方法

技术分享
<script type="text/javascript">
        $(function(){
            spa.initModule(jQuery(‘#spa‘))
        })
</script>
View Code

 

web单页应用(一)

标签:function   container   ted   应用   overflow   charset   事件   title   setting   

原文地址:http://www.cnblogs.com/Nelsen8/p/7076329.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!