使用AngularJS的自适应网站

news/2024/5/9 22:13:10/文章来源:https://blog.csdn.net/cukengwei3786/article/details/107786180
Responsive website using AngularJS
Responsive website using AngularJS

Responsive website using AngularJS In today’s tutorial, I’m going to show you the process of creating almost an entire website with a new library – AngularJS. However, firstly, I would like to introduce to you the AngularJS. AngularJS is a magnificent framework for creating Web applications. This framework lets you extend HTML’s syntax to express your application’s components clearly and succinctly, and lets use standard HTML as your main template language. Plus, it automatically synchronizes data from your UI with your javascript objects through 2-way data binding. If you’ve ever worked with jQuery, the first thing to understand about Angular is that this is a completely different instrument. jQuery – is a library, but AngularJS – is framework. When your code works with the library, it decides when to call a particular function or operator. In the case of the framework, you implement event handlers, and the framework decides at what moment it needs to invoke them.

使用AngularJS的自适应网站在今天的教程中,我将向您展示使用新库AngularJS创建几乎整个网站的过程。 但是,首先,我想向您介绍AngularJS。 AngularJS是用于创建Web应用程序的宏伟框架。 该框架使您可以扩展HTML的语法,以清晰,简洁地表达应用程序的组件,并允许使用标准HTML作为主要模板语言。 另外,它通过2向数据绑定自动将UI中的数据与javascript对象同步。 如果您曾经使用过jQuery,那么了解Angular的第一件事就是这是一种完全不同的工具。 jQuery是一个库,而AngularJS是框架。 当您的代码与库一起使用时,它会决定何时调用特定的函数或运算符。 在框架的情况下,您实现事件处理程序,然后框架决定何时需要调用它们。

Using this framework allows us to clearly distinguish between website templates (DOM), models and functionality (in controllers). Let’s come back to our template, take a look at our result:

使用此框架,我们可以清楚地区分网站模板(DOM),模型和功能(在控制器中)。 让我们回到我们的模板,看看我们的结果:

template preview

template preview
现场演示

[sociallocker]

[社交储物柜]

打包下载

[/sociallocker]

[/ sociallocker]

描述 (Description)

This template is perfect for business sites. It consists of several static pages: the list of projects, privacy and about pages. Each product has its own page. There is also a contact form for communication. That is – all that is necessary for any small website. Moreover, it is also responsive template, thus it looks good on any device.

该模板非常适合企业网站。 它由几个静态页面组成:项目列表,隐私和关于页面。 每个产品都有其自己的页面。 还有一个联系表进行沟通。 那就是–任何小型网站所必需的。 此外,它也是响应式模板,因此在任何设备上看起来都不错。

I hope you liked the demo, so if you’re ready – let’s start making this application. Please prepare a new folder for our project, and then, create next folders in this directory:

我希望您喜欢该演示,所以,如果您准备好了–让我们开始制作此应用程序。 请为我们的项目准备一个新文件夹,然后在此目录中创建下一个文件夹:

  • css – for stylesheet files

    CSS –用于样式表文件
  • images – for image files

    图像–用于图像文件
  • js – for javascript files (libraries, models and controllers)

    js –用于javascript文件(库,模型和控制器)
  • pages – for internal pages

    页面–用于内部页面

阶段1. HTML (Stage 1. HTML)

The main layout consists of four main sections: header with navigation, hidden ‘contact us’ form, main content section and footer. First at all we have to prepare a proper header:

主要布局包括四个主要部分:带有导航的页眉,隐藏的“与我们联系”表单,主要内容部分和页脚。 首先,我们必须准备一个合适的头文件:

index.html (index.html)


<head><meta charset="utf-8" /><meta name="author" content="Script Tutorials" /><title>Responsive website using AngularJS | Script Tutorials</title><meta name="description" content="Responsive website using AngularJS - demo page"><meta http-equiv="X-UA-Compatible" content="IE=Edge" /><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" /><!-- add styles --><link href="css/style.css" rel="stylesheet" type="text/css" /><!-- add javascripts --><script src="js/jquery-2.0.3.min.js"></script><script src="js/angular.min.js"></script><script src="js/app.js"></script><script src="js/controllers.js"></script>
</head>

<head><meta charset="utf-8" /><meta name="author" content="Script Tutorials" /><title>Responsive website using AngularJS | Script Tutorials</title><meta name="description" content="Responsive website using AngularJS - demo page"><meta http-equiv="X-UA-Compatible" content="IE=Edge" /><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" /><!-- add styles --><link href="css/style.css" rel="stylesheet" type="text/css" /><!-- add javascripts --><script src="js/jquery-2.0.3.min.js"></script><script src="js/angular.min.js"></script><script src="js/app.js"></script><script src="js/controllers.js"></script>
</head>

As you can see, it’s quite ordinary header. Now – the header with the navigation:

如您所见,它是非常普通的标头。 现在–带有导航的标题:


<header><div class="wrap"><!-- logo --><a href="#!"><img class="logo" src="images/logo.png" /></a><!-- navigation menu --><nav><ul><li><a id="workBtn" href="#!/" ng-class="{activeSmall:part == 'projects'}" >Our Projects</a></li><li><a id="privacyBtn" href="#!/privacy" ng-class="{activeSmall:part == 'privacy'}">Privacy &amp; Terms</a></li><li><a id="aboutBtn" href="#!/about" ng-class="{activeSmall:part == 'about'}">About</a></li><li style="margin-right:0px"><a id="contactBtn" class="active" href="javascript: void(0)" ng-click="showForm()">Contact Us</a></li></ul></nav></div>
</header>

<header><div class="wrap"><!-- logo --><a href="#!"><img class="logo" src="images/logo.png" /></a><!-- navigation menu --><nav><ul><li><a id="workBtn" href="#!/" ng-class="{activeSmall:part == 'projects'}" >Our Projects</a></li><li><a id="privacyBtn" href="#!/privacy" ng-class="{activeSmall:part == 'privacy'}">Privacy &amp; Terms</a></li><li><a id="aboutBtn" href="#!/about" ng-class="{activeSmall:part == 'about'}">About</a></li><li style="margin-right:0px"><a id="contactBtn" class="active" href="javascript: void(0)" ng-click="showForm()">Contact Us</a></li></ul></nav></div>
</header>

The ordinary logo, the menu is the usual UL-LI menu. Next section is more interesting – ‘Contact Us’ form:

普通徽标,菜单是普通的UL-LI菜单。 下一部分更有趣-“联系我们”表格:


<!-- contact us form -->
<div class="paddRow contactRow"><div class="wrap"><div class="head">Contact Us</div><img class="close" src="images/close.png" ng-click="closeForm()" /><form ng-submit="save()" class="contactForm" name="form" ng-hide="loaded"><input class="input" required="required" type="text" name="name" placeholder="your name" ng-model="message.name" /><input class="input email" required="required" type="email" name="email" value="" placeholder="your email" ng-model="message.email" /><br /><textarea class="textarea" rows="5" required="required" placeholder="your message" ng-model="message.text" ></textarea><button class="btn green">send message</button></form><!-- contact us form response messages --><div ng-show="process" style="text-align:center"><img class="loader" src="images/loader.png" /></div><div ng-show="success"><p>Your message has been sent, thank you.</p></div></div>
</div>

<!-- contact us form -->
<div class="paddRow contactRow"><div class="wrap"><div class="head">Contact Us</div><img class="close" src="images/close.png" ng-click="closeForm()" /><form ng-submit="save()" class="contactForm" name="form" ng-hide="loaded"><input class="input" required="required" type="text" name="name" placeholder="your name" ng-model="message.name" /><input class="input email" required="required" type="email" name="email" value="" placeholder="your email" ng-model="message.email" /><br /><textarea class="textarea" rows="5" required="required" placeholder="your message" ng-model="message.text" ></textarea><button class="btn green">send message</button></form><!-- contact us form response messages --><div ng-show="process" style="text-align:center"><img class="loader" src="images/loader.png" /></div><div ng-show="success"><p>Your message has been sent, thank you.</p></div></div>
</div>

Finally, the last key element: the main content section:

最后,最后一个关键元素:主要内容部分:


<!-- main content -->
<div style="position:relative"><div style="width:100%" ng-view ng-animate="{enter: 'view-enter', leave: 'view-leave'}"></div>
</div>

<!-- main content -->
<div style="position:relative"><div style="width:100%" ng-view ng-animate="{enter: 'view-enter', leave: 'view-leave'}"></div>
</div>

Have you noticed the numerous ‘ng-‘ directives? All these directives allow us to do various actions directly in the DOM, for example:

您是否注意到大量的ng-指令? 所有这些指令使我们能够直接在DOM中执行各种操作,例如:

  • ng-class – the ngClass allows you to set CSS classes on HTML an element, dynamically, by databinding an expression that represents all classes to be added.

    ng-class – ngClass允许您通过绑定表示要添加的所有类的表达式来动态地在HTML元素上设置CSS类。
  • ng-click – the ngClick allows you to specify custom behavior when element is clicked.

    ng-click – ngClick允许您指定单击元素时的自定义行为。
  • ng-hide – the ngHide directive shows and hides the given HTML element conditionally based on the expression provided to the ngHide attribute.

    ng-hide – ngHide指令根据提供给ngHide属性的表达式有条件地显示和隐藏给定HTML元素。
  • ng-include – fetches, compiles and includes an external HTML fragment.

    ng-include –获取,编译并包含一个外部HTML片段。
  • ng-model – is a directive that tells Angular to do two-way data binding.

    ng-model –是一个指令,告诉Angular进行双向数据绑定。
  • ng-show – the ngShow directive shows and hides the given HTML element conditionally based on the expression provided to the ngShow attribute.

    ng-show – ngShow指令根据提供给ngShow属性的表达式有条件地显示和隐藏给定HTML元素。
  • ng-submit – enables binding angular expressions to onsubmit events.

    ng-submit –启用将角度表达式绑定到onsubmit事件。

第2阶段。CSS (Stage 2. CSS)

In this rather large section you can find all the styles used

在这个相当大的部分中,您可以找到所有使用的样式

css / style.css (css/style.css)


/* general settings */
html {min-height:100%;overflow-x:hidden;overflow-y:scroll;position:relative;width:100%;
}
body {background-color:#e6e6e6;color:#FFF;font-weight:100;margin:0;min-height:100%;width:100%;
}
a {text-decoration:none;
}
a img {border:none;
}
h1 {font-size:3.5em;font-weight:100;
}
p {font-size:1.5em;
}
input,textarea {-webkit-appearance:none;background-color:#f7f7f7;border:none;border-radius:3px;font-size:1em;font-weight:100;
}
input:focus,textarea:focus {border:none;outline:2px solid #7ed7b9;
}
.left {float:left;
}
.right {float:right;
}
.btn {background-color:#fff;border-radius:24px;color:#595959;display:inline-block;font-size:1.4em;font-weight:400;margin:30px 0;padding:10px 30px;text-decoration:none;
}
.btn:hover {opacity:0.8;
}
.wrap {-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;margin:0 auto;max-width:1420px;overflow:hidden;padding:0 50px;position:relative;width:100%;
}
.wrap:before {content:'';display:inline-block;height:100%;margin-right:-0.25em;vertical-align:middle;
}
/* header section */
header {height:110px;
}
header .wrap {height:100%;
}
header .logo {margin-top:1px;
}
header nav {float:right;margin-top:17px;
}
header nav ul {margin:1em 0;padding:0;
}
header nav ul li {display:block;float:left;margin-right:20px;
}
header nav ul li a {border-radius:24px;color:#aaa;font-size:1.4em;font-weight:400;padding:10px 27px;text-decoration:none;
}
header nav ul li a.active {background-color:#c33c3a;color:#fff;
}
header nav ul li a.active:hover {background-color:#d2413f;color:#fff;
}
header nav ul li a:hover,header nav ul li a.activeSmall {color:#c33c3a;
}
/* footer section */
footer .copyright {color:#adadad;margin-bottom:50px;margin-top:50px;text-align:center;
}
/* other objects */
.projectObj {color:#fff;display:block;
}
.projectObj .name {float:left;font-size:4em;font-weight:100;position:absolute;width:42%;
}
.projectObj .img {float:right;margin-bottom:5%;margin-top:5%;width:30%;
}
.paddRow {background-color:#dadada;color:#818181;display:none;padding-bottom:40px;
}
.paddRow.aboutRow {background-color:#78c2d4;color:#FFF !important;display:block;
}
.paddRow .head {font-size:4em;font-weight:100;margin:40px 0;
}
.paddRow .close {cursor:pointer;position:absolute;right:50px;top:80px;width:38px;
}
.about {color:#818181;
}
.about section {margin:0 0 10%;
}
.about .head {font-size:4em;font-weight:100;margin:3% 0;
}
.about .subHead {font-size:2.5em;font-weight:100;margin:0 0 3%;
}
.about .txt {width:60%;
}
.about .image {width:26%;
}
.about .flLeft {float:left;
}
.about .flRight {float:right;
}
.projectHead.product {background-color:#87b822;
}
.projectHead .picture {margin-bottom:6%;margin-top:6%;
}
.projectHead .picture.right {margin-right:-3.5%;
}
.projectHead .text {position:absolute;width:49%;
}
.projectHead .centerText {margin:0 auto;padding-bottom:24%;padding-top:6%;text-align:center;width:55%;
}
.image {text-align:center;
}
.image img {vertical-align:top;width:100%;
}
.contactForm {width:50%;
}
.input {-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;margin:1% 0;padding:12px 14px;width:47%;
}
.input.email {float:right;
}
button {border:none;cursor:pointer;
}
.textarea {-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;height:200px;margin:1% 0;overflow:auto;padding:12px 14px;resize:none;width:100%;
}
::-webkit-input-placeholder {color:#a7a7a7;
}
:-moz-placeholder {color:#a7a7a7;
}
::-moz-placeholder { /* FF18+ */color:#a7a7a7;
}
:-ms-input-placeholder {color:#a7a7a7;
}
.loader {-moz-animation:loader_rot 1.3s linear infinite;-o-animation:loader_rot 1.3s linear infinite;-webkit-animation:loader_rot 1.3s linear infinite;animation:loader_rot 1.3s linear infinite;height:80px;width:80px;
}
@-moz-keyframes loader_rot {from {-moz-transform:rotate(0deg);}to {-moz-transform:rotate(360deg);}
}
@-webkit-keyframes loader_rot {from {-webkit-transform:rotate(0deg);}to {-webkit-transform:rotate(360deg);}
}
@keyframes loader_rot {from {transform:rotate(0deg);}to {transform:rotate(360deg);}
}
.view-enter,.view-leave {-moz-transition:all .5s;-o-transition:all .5s;-webkit-transition:all .5s;transition:all .5s;
}
.view-enter {left:20px;opacity:0;position:absolute;top:0;
}
.view-enter.view-enter-active {left:0;opacity:1;
}
.view-leave {left:0;opacity:1;position:absolute;top:0;
}
.view-leave.view-leave-active {left:-20px;opacity:0;
}

/* general settings */
html {min-height:100%;overflow-x:hidden;overflow-y:scroll;position:relative;width:100%;
}
body {background-color:#e6e6e6;color:#FFF;font-weight:100;margin:0;min-height:100%;width:100%;
}
a {text-decoration:none;
}
a img {border:none;
}
h1 {font-size:3.5em;font-weight:100;
}
p {font-size:1.5em;
}
input,textarea {-webkit-appearance:none;background-color:#f7f7f7;border:none;border-radius:3px;font-size:1em;font-weight:100;
}
input:focus,textarea:focus {border:none;outline:2px solid #7ed7b9;
}
.left {float:left;
}
.right {float:right;
}
.btn {background-color:#fff;border-radius:24px;color:#595959;display:inline-block;font-size:1.4em;font-weight:400;margin:30px 0;padding:10px 30px;text-decoration:none;
}
.btn:hover {opacity:0.8;
}
.wrap {-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;margin:0 auto;max-width:1420px;overflow:hidden;padding:0 50px;position:relative;width:100%;
}
.wrap:before {content:'';display:inline-block;height:100%;margin-right:-0.25em;vertical-align:middle;
}
/* header section */
header {height:110px;
}
header .wrap {height:100%;
}
header .logo {margin-top:1px;
}
header nav {float:right;margin-top:17px;
}
header nav ul {margin:1em 0;padding:0;
}
header nav ul li {display:block;float:left;margin-right:20px;
}
header nav ul li a {border-radius:24px;color:#aaa;font-size:1.4em;font-weight:400;padding:10px 27px;text-decoration:none;
}
header nav ul li a.active {background-color:#c33c3a;color:#fff;
}
header nav ul li a.active:hover {background-color:#d2413f;color:#fff;
}
header nav ul li a:hover,header nav ul li a.activeSmall {color:#c33c3a;
}
/* footer section */
footer .copyright {color:#adadad;margin-bottom:50px;margin-top:50px;text-align:center;
}
/* other objects */
.projectObj {color:#fff;display:block;
}
.projectObj .name {float:left;font-size:4em;font-weight:100;position:absolute;width:42%;
}
.projectObj .img {float:right;margin-bottom:5%;margin-top:5%;width:30%;
}
.paddRow {background-color:#dadada;color:#818181;display:none;padding-bottom:40px;
}
.paddRow.aboutRow {background-color:#78c2d4;color:#FFF !important;display:block;
}
.paddRow .head {font-size:4em;font-weight:100;margin:40px 0;
}
.paddRow .close {cursor:pointer;position:absolute;right:50px;top:80px;width:38px;
}
.about {color:#818181;
}
.about section {margin:0 0 10%;
}
.about .head {font-size:4em;font-weight:100;margin:3% 0;
}
.about .subHead {font-size:2.5em;font-weight:100;margin:0 0 3%;
}
.about .txt {width:60%;
}
.about .image {width:26%;
}
.about .flLeft {float:left;
}
.about .flRight {float:right;
}
.projectHead.product {background-color:#87b822;
}
.projectHead .picture {margin-bottom:6%;margin-top:6%;
}
.projectHead .picture.right {margin-right:-3.5%;
}
.projectHead .text {position:absolute;width:49%;
}
.projectHead .centerText {margin:0 auto;padding-bottom:24%;padding-top:6%;text-align:center;width:55%;
}
.image {text-align:center;
}
.image img {vertical-align:top;width:100%;
}
.contactForm {width:50%;
}
.input {-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;margin:1% 0;padding:12px 14px;width:47%;
}
.input.email {float:right;
}
button {border:none;cursor:pointer;
}
.textarea {-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;height:200px;margin:1% 0;overflow:auto;padding:12px 14px;resize:none;width:100%;
}
::-webkit-input-placeholder {color:#a7a7a7;
}
:-moz-placeholder {color:#a7a7a7;
}
::-moz-placeholder { /* FF18+ */color:#a7a7a7;
}
:-ms-input-placeholder {color:#a7a7a7;
}
.loader {-moz-animation:loader_rot 1.3s linear infinite;-o-animation:loader_rot 1.3s linear infinite;-webkit-animation:loader_rot 1.3s linear infinite;animation:loader_rot 1.3s linear infinite;height:80px;width:80px;
}
@-moz-keyframes loader_rot {from {-moz-transform:rotate(0deg);}to {-moz-transform:rotate(360deg);}
}
@-webkit-keyframes loader_rot {from {-webkit-transform:rotate(0deg);}to {-webkit-transform:rotate(360deg);}
}
@keyframes loader_rot {from {transform:rotate(0deg);}to {transform:rotate(360deg);}
}
.view-enter,.view-leave {-moz-transition:all .5s;-o-transition:all .5s;-webkit-transition:all .5s;transition:all .5s;
}
.view-enter {left:20px;opacity:0;position:absolute;top:0;
}
.view-enter.view-enter-active {left:0;opacity:1;
}
.view-leave {left:0;opacity:1;position:absolute;top:0;
}
.view-leave.view-leave-active {left:-20px;opacity:0;
}

Please note, that CSS3 transitions are used, it means that our demonstration will only work in most modern browsers (FF, Chrome, IE10+ etc)

请注意,使用了CSS3过渡,这意味着我们的演示仅适用于大多数现代浏览器(FF,Chrome,IE10 +等)

第三阶段。JavaScript (Stage 3. JavaScript)

As I mentioned before, our main controller and the model are separated. The navigation menu can be handled here, and we also can operate with the contact form.

如前所述,我们的主控制器和模型是分开的。 导航菜单可以在此处处理,我们也可以使用联系表进行操作。

js / app.js (js/app.js)


'use strict';
// angular.js main app initialization
var app = angular.module('example359', []).config(['$routeProvider', function ($routeProvider) {$routeProvider.when('/', { templateUrl: 'pages/index.html', activetab: 'projects', controller: HomeCtrl }).when('/project/:projectId', {templateUrl: function (params) { return 'pages/' + params.projectId + '.html'; },controller: ProjectCtrl,activetab: 'projects'}).when('/privacy', {templateUrl: 'pages/privacy.html',controller: PrivacyCtrl,activetab: 'privacy'}).when('/about', {templateUrl: 'pages/about.html',controller: AboutCtrl,activetab: 'about'}).otherwise({ redirectTo: '/' });}]).run(['$rootScope', '$http', '$browser', '$timeout', "$route", function ($scope, $http, $browser, $timeout, $route) {$scope.$on("$routeChangeSuccess", function (scope, next, current) {$scope.part = $route.current.activetab;});// onclick event handlers$scope.showForm = function () {$('.contactRow').slideToggle();};$scope.closeForm = function () {$('.contactRow').slideUp();};// save the 'Contact Us' form$scope.save = function () {$scope.loaded = true;$scope.process = true;$http.post('sendemail.php', $scope.message).success(function () {$scope.success = true;$scope.process = false;});};}]);
app.config(['$locationProvider', function($location) {$location.hashPrefix('!');
}]);

'use strict';
// angular.js main app initialization
var app = angular.module('example359', []).config(['$routeProvider', function ($routeProvider) {$routeProvider.when('/', { templateUrl: 'pages/index.html', activetab: 'projects', controller: HomeCtrl }).when('/project/:projectId', {templateUrl: function (params) { return 'pages/' + params.projectId + '.html'; },controller: ProjectCtrl,activetab: 'projects'}).when('/privacy', {templateUrl: 'pages/privacy.html',controller: PrivacyCtrl,activetab: 'privacy'}).when('/about', {templateUrl: 'pages/about.html',controller: AboutCtrl,activetab: 'about'}).otherwise({ redirectTo: '/' });}]).run(['$rootScope', '$http', '$browser', '$timeout', "$route", function ($scope, $http, $browser, $timeout, $route) {$scope.$on("$routeChangeSuccess", function (scope, next, current) {$scope.part = $route.current.activetab;});// onclick event handlers$scope.showForm = function () {$('.contactRow').slideToggle();};$scope.closeForm = function () {$('.contactRow').slideUp();};// save the 'Contact Us' form$scope.save = function () {$scope.loaded = true;$scope.process = true;$http.post('sendemail.php', $scope.message).success(function () {$scope.success = true;$scope.process = false;});};}]);
app.config(['$locationProvider', function($location) {$location.hashPrefix('!');
}]);

Pay attention, when we request a page, it loads an appropriate page from the ‘pages’ folder: about.html, privacy.html, index.html. Depending on selected product, it opens one of product pages: product1.html, product2.html, product3.html or product4.html

请注意,当我们请求页面时,它将从“页面”文件夹中加载适当的页面:about.html,privacy.html,index.html。 根据所选产品,它会打开产品页面之一:product1.html,product2.html,product3.html或product4.html

In the second half there are functions to slide the contact form and to handle with it’s submit process (to the sendemail.php page). Next is the controller file:

在第二部分中,有一些功能可以滑动联系表单并处理其提交过程(到sendemail.php页面)。 接下来是控制器文件:

js / controllers.js (js/controllers.js)


'use strict';
// optional controllers
function HomeCtrl($scope, $http) {
}
function ProjectCtrl($scope, $http) {
}
function PrivacyCtrl($scope, $http, $timeout) {
}
function AboutCtrl($scope, $http, $timeout) {
}

'use strict';
// optional controllers
function HomeCtrl($scope, $http) {
}
function ProjectCtrl($scope, $http) {
}
function PrivacyCtrl($scope, $http, $timeout) {
}
function AboutCtrl($scope, $http, $timeout) {
}

It is empty, because we have nothing to use here at the moment

它是空的,因为目前我们在这里无用

第4阶段。其他页面 (Stage 4. Additional pages)

AngularJS loads pages asynchronous, thereby increasing the speed. Here are templates of all additional pages used in our project:

AngularJS异步加载页面,从而提高了速度。 以下是我们项目中使用的所有其他页面的模板:

pages / about.html (pages/about.html)


<div style="width:100%"><div class="paddRow aboutRow"><div class="wrap"><div class="head">About Us</div><p>Script Tutorials is one of the largest web development communities. We provide high quality content (articles and tutorials) which covers all the web development technologies including HTML5, CSS3, Javascript (and jQuery), PHP and so on. Our audience are web designers and web developers who work with web technologies.</p></div></div><div style="background-color:#f5f5f5"><div class="wrap about"><div class="head">Additional information</div><section><div class="image flRight"><img src="images/ang.png" class="abIcon"></div><div class="txt flLeft"><h2 class="subHead">Promo 1</h2><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc et ligula accumsan, pharetra nibh nec, facilisis nulla. In pretium semper venenatis. In adipiscing augue elit, at venenatis enim suscipit a. Fusce vitae justo tristique, ultrices mi metus.</p></div><div style="clear:both"></div></section>.....</div></div><ng-include src="'pages/footer.html'"></ng-include>
</div>

<div style="width:100%"><div class="paddRow aboutRow"><div class="wrap"><div class="head">About Us</div><p>Script Tutorials is one of the largest web development communities. We provide high quality content (articles and tutorials) which covers all the web development technologies including HTML5, CSS3, Javascript (and jQuery), PHP and so on. Our audience are web designers and web developers who work with web technologies.</p></div></div><div style="background-color:#f5f5f5"><div class="wrap about"><div class="head">Additional information</div><section><div class="image flRight"><img src="images/ang.png" class="abIcon"></div><div class="txt flLeft"><h2 class="subHead">Promo 1</h2><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc et ligula accumsan, pharetra nibh nec, facilisis nulla. In pretium semper venenatis. In adipiscing augue elit, at venenatis enim suscipit a. Fusce vitae justo tristique, ultrices mi metus.</p></div><div style="clear:both"></div></section>.....</div></div><ng-include src="'pages/footer.html'"></ng-include>
</div>

pages / privacy.html (pages/privacy.html)


<div style="width:100%"><div class="paddRow aboutRow"><div class="wrap"><div class="head">Privacy &amp; Terms</div><p> By accessing this web site, you are agreeing to be bound by these web site Terms and Conditions of Use, all applicable laws and regulations, and agree that you are responsible for compliance with any applicable local laws. If you do not agree with any of these terms, you are prohibited from using or accessing this site. The materials contained in this web site are protected by applicable copyright and trade mark law.</p></div></div><div style="background-color:#f5f5f5"><div class="wrap about"><div class="head">Other information</div><section><div class="image flLeft"><img src="images/ang.png" class="abIcon"></div><div class="txt flRight"><h2 class="subHead">Header 1</h2><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc et ligula accumsan, pharetra nibh nec, facilisis nulla. In pretium semper venenatis. In adipiscing augue elit, at venenatis enim suscipit a. Fusce vitae justo tristique, ultrices mi metus.</p></div><div style="clear:both"></div></section>.....</div></div><ng-include src="'pages/footer.html'"></ng-include>
</div>

<div style="width:100%"><div class="paddRow aboutRow"><div class="wrap"><div class="head">Privacy &amp; Terms</div><p> By accessing this web site, you are agreeing to be bound by these web site Terms and Conditions of Use, all applicable laws and regulations, and agree that you are responsible for compliance with any applicable local laws. If you do not agree with any of these terms, you are prohibited from using or accessing this site. The materials contained in this web site are protected by applicable copyright and trade mark law.</p></div></div><div style="background-color:#f5f5f5"><div class="wrap about"><div class="head">Other information</div><section><div class="image flLeft"><img src="images/ang.png" class="abIcon"></div><div class="txt flRight"><h2 class="subHead">Header 1</h2><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc et ligula accumsan, pharetra nibh nec, facilisis nulla. In pretium semper venenatis. In adipiscing augue elit, at venenatis enim suscipit a. Fusce vitae justo tristique, ultrices mi metus.</p></div><div style="clear:both"></div></section>.....</div></div><ng-include src="'pages/footer.html'"></ng-include>
</div>

pages / footer.html (pages/footer.html)


<footer><div class="copyright"><a href="https://www.script-tutorials.com/" target="_blank">Copyright © 2013 Script Tutorials</a></div>
</footer>

<footer><div class="copyright"><a href="https://www.script-tutorials.com/" target="_blank">Copyright © 2013 Script Tutorials</a></div>
</footer>

pages / index.html (pages/index.html)


<div style="width:100%"><a class="projectObj" href="#!/project/product1" style="background-color:#87b822"><div class="wrap"><div class="name">Product #1</div><img class="img" src="images/element.png" /></div></a><a class="projectObj" href="#!/project/product2" style="background-color:#3f91d2"><div class="wrap"><div class="name">Product #2</div><img class="img" src="images/element.png" /></div></a><a class="projectObj" href="#!/project/product3" style="background-color:#f1784d"><div class="wrap"><div class="name">Product #3</div><img class="img" src="images/element.png" /></div></a><a class="projectObj" href="#!/project/product4" style="background-color:#f0c42c"><div class="wrap"><div class="name">Product #4</div><img class="img" src="images/element.png" /></div></a><ng-include src="'pages/footer.html'"></ng-include>
</div>
<script>
$('.projectObj').bind('click', function (e) {e.preventDefault();var me = this;var width = $(me).width() / 1.5;$(me).find('.wrap').width($(me).find('.wrap').width());$(me).animate({opacity: 0,marginLeft: -width}, 500);var delayN = 150;var delayP = 150;var nextEl = $(me).nextAll('.projectObj');var prevEl = $(me).prevAll('.projectObj');nextEl.each(function (index, elem) {setTimeout(function () {$(elem).find('.wrap').width($(elem).find('.wrap').width());$(elem).animate({opacity: 0,marginLeft: -width}, 500, function () {});}, delayN);delayN += 100;});prevEl.each(function (index, elem) {setTimeout(function () {$(elem).find('.wrap').width($(elem).find('.wrap').width());$(elem).animate({opacity: 0,marginLeft: -width}, 500, function () {});}, delayP);delayP += 100;});setTimeout(function () {document.location = $(me).attr('href');},1000)return false;
});
</script>

<div style="width:100%"><a class="projectObj" href="#!/project/product1" style="background-color:#87b822"><div class="wrap"><div class="name">Product #1</div><img class="img" src="images/element.png" /></div></a><a class="projectObj" href="#!/project/product2" style="background-color:#3f91d2"><div class="wrap"><div class="name">Product #2</div><img class="img" src="images/element.png" /></div></a><a class="projectObj" href="#!/project/product3" style="background-color:#f1784d"><div class="wrap"><div class="name">Product #3</div><img class="img" src="images/element.png" /></div></a><a class="projectObj" href="#!/project/product4" style="background-color:#f0c42c"><div class="wrap"><div class="name">Product #4</div><img class="img" src="images/element.png" /></div></a><ng-include src="'pages/footer.html'"></ng-include>
</div>
<script>
$('.projectObj').bind('click', function (e) {e.preventDefault();var me = this;var width = $(me).width() / 1.5;$(me).find('.wrap').width($(me).find('.wrap').width());$(me).animate({opacity: 0,marginLeft: -width}, 500);var delayN = 150;var delayP = 150;var nextEl = $(me).nextAll('.projectObj');var prevEl = $(me).prevAll('.projectObj');nextEl.each(function (index, elem) {setTimeout(function () {$(elem).find('.wrap').width($(elem).find('.wrap').width());$(elem).animate({opacity: 0,marginLeft: -width}, 500, function () {});}, delayN);delayN += 100;});prevEl.each(function (index, elem) {setTimeout(function () {$(elem).find('.wrap').width($(elem).find('.wrap').width());$(elem).animate({opacity: 0,marginLeft: -width}, 500, function () {});}, delayP);delayP += 100;});setTimeout(function () {document.location = $(me).attr('href');},1000)return false;
});
</script>

Finally, the product pages. All of them are prototype, so I decided to publish only one of them.

最后是产品页面。 它们都是原型,所以我决定只发布其中之一。

pages / index.html (pages/index.html)


<div style="width:100%"><div class="projectHead product"><div class="wrap"><div class="text left"><h1>Product 1 page</h1><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc et ligula accumsan, pharetra nibh nec, facilisis nulla. In pretium semper venenatis. In adipiscing augue elit, at venenatis enim suscipit a. Fusce vitae justo tristique, ultrices mi metus.</p><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc et ligula accumsan, pharetra nibh nec, facilisis nulla. In pretium semper venenatis. In adipiscing augue elit, at venenatis enim suscipit a. Fusce vitae justo tristique, ultrices mi metus.</p><a class="btn" href="javascript: void(0)">download the app</a></div><img class="picture right" src="images/element.png" /><div style="clear:both"></div></div></div><ng-include src="'pages/footer.html'"></ng-include>
</div>

<div style="width:100%"><div class="projectHead product"><div class="wrap"><div class="text left"><h1>Product 1 page</h1><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc et ligula accumsan, pharetra nibh nec, facilisis nulla. In pretium semper venenatis. In adipiscing augue elit, at venenatis enim suscipit a. Fusce vitae justo tristique, ultrices mi metus.</p><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc et ligula accumsan, pharetra nibh nec, facilisis nulla. In pretium semper venenatis. In adipiscing augue elit, at venenatis enim suscipit a. Fusce vitae justo tristique, ultrices mi metus.</p><a class="btn" href="javascript: void(0)">download the app</a></div><img class="picture right" src="images/element.png" /><div style="clear:both"></div></div></div><ng-include src="'pages/footer.html'"></ng-include>
</div>

画龙点睛-响应式风格 (Finishing touches – responsive styles)

All of these styles are needed to make our results look equally well on all possible mobile devices and monitors:

所有这些样式都需要使我们的结果在所有可能的移动设备和监视器上看起来都一样好:


@media (max-width: 1200px) {body {font-size:90%;}h1 {font-size:4.3em;}p {font-size:1.3em;}header {height:80px;}header .logo {margin-top:12px;width:200px;}header nav {margin-top:11px;}header nav ul li {margin-right:12px;}header nav ul li a {border-radius:23px;font-size: 1.3em;padding:10px 12px;}.wrap {padding:0 30px;}.paddRow .close {right:30px;}
}
@media (max-width: 900px) {.contactForm {width:100%;}
}
@media (max-width: 768px) {body {font-size:80%;margin:0;}h1 {font-size:4em;}header {height:70px;}header .logo {margin-top:20px;width:70px;}header nav {margin-top:8px;}header nav ul li {margin-right:5px;}header nav ul li a {border-radius:20px;font-size:1.1em;padding:8px;}.wrap {padding:0 15px;}.projectObj .name {font-size:3em;}.paddRow {padding-bottom:30px;}.paddRow .head {font-size:3em;margin:30px 0;}.paddRow .close {right:20px;top:60px;width:30px;}.projectHead .picture {width:67%;}.projectHead .picture.right {margin-right:16.5%;}.projectHead .text {position:static;width:100%;}.projectHead .centerText {width:70%;}.view-enter,.view-leave {-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0);}
}
@media (max-width: 480px) {body {font-size:70%;margin:0;}header {height:50px;}header .logo {display:none;}header nav {margin-top:3px;}header nav ul li {margin-right:3px;}header nav ul li a {border-radius:20px;font-size:1.3em;padding:5px 14px;}#contactBtn {display:none;}.wrap {padding:0 10px;}.paddRow {padding-bottom:20px;}.paddRow .head {margin:20px 0;}.paddRow .close {right:10px;top:45px;width:20px;}.about .image {margin:10% auto;width:60%;}.about .abIcon {display:inline;}.projectHead .centerText {width:90%;}.about .txt,.input {width:100%;}.about .flLeft,.about .flRight,.input.email {float:none;}
}

@media (max-width: 1200px) {body {font-size:90%;}h1 {font-size:4.3em;}p {font-size:1.3em;}header {height:80px;}header .logo {margin-top:12px;width:200px;}header nav {margin-top:11px;}header nav ul li {margin-right:12px;}header nav ul li a {border-radius:23px;font-size: 1.3em;padding:10px 12px;}.wrap {padding:0 30px;}.paddRow .close {right:30px;}
}
@media (max-width: 900px) {.contactForm {width:100%;}
}
@media (max-width: 768px) {body {font-size:80%;margin:0;}h1 {font-size:4em;}header {height:70px;}header .logo {margin-top:20px;width:70px;}header nav {margin-top:8px;}header nav ul li {margin-right:5px;}header nav ul li a {border-radius:20px;font-size:1.1em;padding:8px;}.wrap {padding:0 15px;}.projectObj .name {font-size:3em;}.paddRow {padding-bottom:30px;}.paddRow .head {font-size:3em;margin:30px 0;}.paddRow .close {right:20px;top:60px;width:30px;}.projectHead .picture {width:67%;}.projectHead .picture.right {margin-right:16.5%;}.projectHead .text {position:static;width:100%;}.projectHead .centerText {width:70%;}.view-enter,.view-leave {-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0);}
}
@media (max-width: 480px) {body {font-size:70%;margin:0;}header {height:50px;}header .logo {display:none;}header nav {margin-top:3px;}header nav ul li {margin-right:3px;}header nav ul li a {border-radius:20px;font-size:1.3em;padding:5px 14px;}#contactBtn {display:none;}.wrap {padding:0 10px;}.paddRow {padding-bottom:20px;}.paddRow .head {margin:20px 0;}.paddRow .close {right:10px;top:45px;width:20px;}.about .image {margin:10% auto;width:60%;}.about .abIcon {display:inline;}.projectHead .centerText {width:90%;}.about .txt,.input {width:100%;}.about .flLeft,.about .flRight,.input.email {float:none;}
}

现场演示

结论 (Conclusion)

That’s all for today, thanks for your patient attention, and if you really like what we did today – share it with all your friends in your social networks using the form below.

今天就这些,感谢您耐心的关注,如果您真的喜欢我们今天的工作,请使用下面的表格与您社交网络中的所有朋友分享。

翻译自: https://www.script-tutorials.com/responsive-website-using-angularjs/

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_893992.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

大型网站架构演变和知识体系

之前也有一些介绍大型网站架构演变的文章&#xff0c;例如 LiveJournal 的、 ebay 的&#xff0c;都是非常值得参考的&#xff0c;不过感觉他们讲的更多的是每次演变的结果&#xff0c;而没有很详细的讲为什么需要做这样的演变&#xff0c;再加上近来感觉有不少同学都很难明白为…

chrome无法从该网站添加应用、扩展程序和用户脚本的有效解决方法

1.情景展示 在安装chrome离线扩展程序时&#xff0c;报错信息如下&#xff1a; 2.解决方案 第一步&#xff1a; 新建一个标签页&#xff0c;在地址栏输入&#xff1a;chrome://flags/#extensions-on-chrome-urls并按回车键 将值改为enabled 重启chrome 第二步&#xff1a…

win7 、IIS7.0 搭建ASP网站

工具/原料 Windows7系统 &#xff08;IIS是WIN7自带的&#xff0c;版本7.0&#xff09; 步骤/方法 首先是安装IIS。打开控制面板&#xff0c;找到“程序与功能”&#xff0c;点进去 点击左侧“打开或关闭Windows功能” 找到“Internet 信息服务”&#xff0c;按照下图打勾即可…

从零开始用云服务器 Ubuntu 18.04 安装wordpress基础的+配置过程搭建个人网站

购买服务器 我用的是华为云服务器 从开始买云服务器先点控制台在点击弹性云服务器ECS 然后买好后 点击远程登录即可打开 我选的是云服务器ecs&#xff0c;系统选的ubuntu 18.04&#xff0c;搭建时注意要记住登录密码 配置安全组 然后首先配置一下安全组 可以按下列步骤找到…

19款网站常见多图片自动轮播banner源码

19款网站常见多图片自动轮播banner源码 http://bbs.blueidea.com/thread-2729702-1-1.html 点击图片进入下载页 点击文字查看效果演示 韩国滚动图片banner17(仿三维空间前后替换) 韩国滚动图片banner16(左右滚动) 韩国滚动图片banner15(定时滚动) 韩国滚动图片banner14(定时滚…

ASP.NET2.0中themes、Skins轻松实现网站换肤!

可能有些朋友还不是很清楚themes、skins。下面先介绍下themes、skins.。一、简介&#xff1a;一看Themes、Skins这2名字就都知道是用来做什么的了吧&#xff0c;下面就说下它是做什么的(怎么都知道了还说,~_~)&#xff0c;利用Themes我们可以很容易的更改控件、页面的风格&…

vue-i18n 网站中英文切换插件的基本使用

最近项目中用到国际化之前看到一个博客写的vue-i18n的使用非常好&#xff0c;后来就找不到是哪个了心塞。 vue-i18n的基本使用 首先肯定是下载啦&#xff01; npm install vue-i18n --save 然后在src下边新建一个i8n文件夹 //cn.js// import zhLocale from element-ui/lib/loc…

利用Github建立你的个人网站

http://blog.csdn.net/u012422829/article/details/46285577 这两天用了Github建立了自己的个人主页&#xff0c; 网址为 hyman1994.com。 感兴趣的朋友可以访问一下&#xff0c;欢迎您的指导意见和建议&#xff01; 流程总结&#xff1a; 1.注册自己的github账户,名为XXX 2.创…

网站收藏夹图标 添加代码

首先制作一个16x16的icon图标&#xff0c;命名为favicon.ico&#xff0c;放在根目录下。然后将下面的代码嵌入head区&#xff1a; <link rel"icon" href"/favicon.ico" type"image/x-icon" /><link rel"shortcut icon" href&…

SEO教程:链接策略(Link Wheel)

为什么链接也需要策略? SEO需要策略&#xff0c;而且需要系统性的执行。而不是盲目的更新文章&#xff0c;添加外连。内链需要策略&#xff0c;外链需要策略&#xff0c;关键字需要策略……为什么我们网站的黑链掉了&#xff0c;排名就会有所下降。那是因为我们太过单一性。黑…

一步步构建大型网站架构 转载

之前我简单向大家介绍了各个知名大型网站的架构&#xff0c;MySpace的五个里程碑 、Flickr的架构 、YouTube的架构 、PlentyOfFish的架构 、WikiPedia的架构 。这几个都很典型&#xff0c;我们可以从中获取很多有关网站架构方面的知识&#xff0c;看了之后你会发现你原来的想法…

使用 PHP、JavaScript 和 WURFL 的设备识别移动网站

不再为移动设备功能而迷茫 随着移动 Web 的快速发展&#xff0c;如果您还没有使用过 PHP 驱动的移动网站或应用程序&#xff0c;那么您很快就会用到。在数以千计的产品中检测一个移动设备的功能&#xff0c;仅使用 PHP 几乎是不可能实现的。但是有了 Wireless Universal Resour…

亿愿网站各类文件自动全部下载

亿愿网站各类文件自动全部下载(yywebsitedownall)-简介 ---席卷网站的龙卷风&#xff0c;一网打尽各类网站的各种类型文件&#xff01;---不留死角的网站"爬虫"&#xff01;兼容绝大部分高新技术制作的网站!---万能下载器&#xff01;多线程,多文件,智能识别文件名的…

记录--如何搭建自己的网站(阿里云)--(一)

记录–如何搭建自己的网站&#xff08;阿里云&#xff09;&#xff08;一&#xff09; 在网上看了好多帖子&#xff0c;恕我理解能力有限&#xff0c;只看个半懂&#xff0c;自己鼓捣了好久才弄出来&#xff0c;所以记录一下自己的心路历程&#xff0c;也方便以后查阅。 第一…

Java实战项目之精品课程网站【源码+课后指导】_Java毕业设计/计算机毕业设计

可以用来做毕业设计的Java实战项目又双叒叕来啦&#xff01;快来学习吧~Java实战项目之精品课程网站【源码课后指导】_Java毕业设计/计算机毕业设计https://www.bilibili.com/video/BV1dq4y1h7Z2 Java多态性&#xff1a;Java什么是多态&#xff1f; 态性是面向对象编程的又一个…

【源码+项目部署】Java课程设计_精品课程网站_Java毕业设计_Java毕设项目_Java课设项目_Java实战项目_Java开源项目_计算机毕业设计

小伙伴们的课程设计应该都做的差不多了吧&#xff0c;还没搞定的小伙伴要抓紧时间了喔~ 本篇为大家带来的Java开源项目是精品课程网站&#xff01;快来学习吧~【源码项目部署】Java课程设计_精品课程网站_Java毕业设计_Java毕设项目_Java课设项目_Java实战项目_Java开源项目_计…

常用SEO查询工具

SEO工作者经常需要一些SEO工具的辅助&#xff0c;比如网站收录查询、PR查询等等&#xff0c;以便节省自己的时间&#xff0c;让SEO变得更加轻松。那么&#xff0c;常用的SEO工具都有哪些呢&#xff1f;月光博客今天就介绍一些常用的SEO工具网址&#xff0c;并将其进行分类&…

电子商务网站系统 iWebShop

iWebShop 是一款面向独立卖家的单用户开源网店系统&#xff0c;基于PHPMySQL框架开发&#xff0c;通过它可以迅速建立起一个B2C网上商城。 iWebShop基于iWebSI框架开发&#xff0c;在获得iWebSI技术平台库支持的条件下&#xff0c;iWebShop可以轻松满足用户量级百万至千万级的 …

开源企业网站建设系统 ASPCMS

2.0.0是上谷网络旗下aspcms开发的全新内核的开源企业建站系统&#xff0c;能够胜任企业多种建站需求&#xff0c;并且支持模版自定义、支持扩展插件等等&#xff0c;能够在短时间内完成企业建站。 ASPCMS 开源企业网站管理系统功能列表&#xff1a;1、支持一键生成html&#xf…

互联网网站的反爬虫策略浅析

因为搜索引擎的流行&#xff0c;网络爬虫已经成了很普及网络技术&#xff0c;除了专门做搜索的Google&#xff0c;Yahoo&#xff0c;微软&#xff0c;百度以外&#xff0c;几乎每个大型门户网站都有自己的搜索引擎&#xff0c;大大小小叫得出来名字得就几十种&#xff0c;还有各…