源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

AngularJS实现网站换肤实例

  • 时间:2020-09-24 12:27 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:AngularJS实现网站换肤实例
网站不应该只注重功能,还应该注重用户体验;成熟的大型网站大都具备让用户自行选择主题及颜色的功能,AngularJS也可以做到这点。 效果图: [img]http://files.jb51.net/file_images/article/201612/2016122894421119.gif?2016112894554[/img] 原理是使用ng-href来动态为网页更换样式: <link rel="stylesheet" type="text/css" ng-href="{{theme.value}}.css"> 代码:
<!DOCTYPE html>
<html ng-app="app" ng-controller="mainCtrl">
<head >
 <meta charset="UTF-8">
 <title></title>
 //动态更新CSS样式
 <link rel="stylesheet" type="text/css" ng-href="{{theme.value}}.css">
 <script src="../angular.js"></script>
 <style type="text/css">
  h1{
   font-style:italic;
  }
 </style>
 <script type="text/javascript">
  angular.module("app", [])
   .controller("mainCtrl", function($scope){
    $scope.options = [
     {
      name:"蓝色",
      value:"blue"
     },
     {
      name:"红色",
      value:"red"
     }
    ];
    //默认选择第一个样式
    $scope.theme = $scope.options[0];
   })
 </script>
</head>
<body>
 <select ng-model="theme" ng-options="c.name for c in options">
 </select>
 <h1>Welcome</h1>
 <ul>
  <li>Home</li>
  <li>About</li>
  <li>Contact</li>
 </ul>
</body>
</html>
blue.css
h1{
 color:blue;
}
ul li{
 display:inline-block;
}

red.css
h1{
 color:red;
}
此文档的作者:[url=http://www.justforuse.cn/wordpress/]justforuse [/url] Github Pages:[url=http://justforuse.github.io/]justforuse [/url] 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部