web單頁應用(一)

來源:互聯網
上載者:User

標籤: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 spavar 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單頁應用(一)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.