<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>quick work</title>
<script type="text/javascript" src="../jquery.js"></script>
<script type="text/javascript" src="../angular-1.4.1/angular-1.4.1/angular.js"></script>
<style type="text/css">
*{
margin: 0 auto;
padding: 0px;
}
li{
list-style: none;
}
.total {
width: 640px;
height: auto;
border:1px solid #333;
}
.total_top{
border : 1px solid #333;
margin: 20px;
height: 100px;
overflow: hidden;
}
.total_bottom {
width: 100%;
height: 60px;
border-top: 1px solid #333;
display: inline-flex;
align-items: center;
}
ul {
width: 400%;
height: 100px;
overflow: hidden;
}
.moveDiv{
height: 100px;
width: 100%;
}
ul li{
height: 100%;
display: block;
float: left;
}
.total_bottom span {
font-size: 20px;
color: #000;
display: block;
width: 60px;
height: 60px;
text-align: center;
line-height: 60px;
cursor: pointer;
margin: 0px;
}
.total_bottom_left{
border-right: 1px solid #333;
float: left; }
.total_bottom_right{
border-left: 1px solid #333;
float: right; }
.bottom_cen {
margin: 0 auto;
text-align: center;
float: left;
}
.bottom_cen a{
width: 15px;
height: 5px;
background-color: #000;
float: left;
margin-right: 10px;
}
</style>
</head>
<body ng-app = "quickApp">
<div ng-controller = "quickController">
<div class="total">
<total-content dataset-data = "totalData" li-width = "width" clickindex = "clickM(index)"></total-content>
<!-- <div class="total_top">
<ul>
<li ng-repeat = "data in totalData">{{data.content}}</li>
</ul>
</div>
<div> <quick-boor dataset-data = "totalData" ></quick-boor>
</div> -->
</div>
</div>
</body>
<script type="text/javascript">
var app =angular.module("quickApp",[]);
app.controller("quickController",function($scope,$timeout){
$timeout(function() {
angular.element(".total_top ul li").css({"width" : $(".total_top").width() + "px"});
$scope.width = $(".total_top").width();
});
$scope.totalData = [{
"content" : "111111111"
},{
"content" : "222222222"
},{
"content" : "3333333333"
}];
// --------1
// $scope.clickM = function(index){
// angular.element(".total_top ul").stop().animate({marginLeft : - $scope.width * index + "px"},500);
// }
})
.directive("totalContent",function($timeout){
return {
restrict : 'E',
replace : true,
scope : {
datasetData : "=",
liWidth : "="
// liWidth : "=", ------1
// clickindex : "&" -----1
},
template : '<div><div class="total_top">'+
'<ul>'+
'<li ng-repeat = "data in datasetData">{{data.content}}</li>'+
'</ul>'+
'</div><div class="total_bottom">' +
'<span class="total_bottom_left" ng-click = "onClickLeft()"><</span>'+
'<div class="bottom_cen">' +
// ng-click="clickindex({index : $index}) 1
'<a href="#" ng-repeat = "data in datasetData" ng-click="clickindex($index)"></a>' +
'</div>' +
'<span class="total_bottom_right" ng-click = "onClickRight()">></span>' +
'</div>' +
'</div></div>',
link : function(scope,elem,attrs) {
// $timeout(function() {
// angular.element(".total_top ul li").css({"width" : angular.element(".total_top").width() + "px"});
// scope.width = angular.element(".total_top").width();
// }); scope.index = 0; scope.clickindex = function(index){
scope.index = index
angular.element(".total_top ul").stop().animate({marginLeft : - scope.liWidth * index + "px"},500);
}
scope.onClickLeft = function(){
if(scope.index < angular.element(".total_top ul li").length - 1 && scope.index >= 0){
scope.index ++;
angular.element(".total_top ul").stop().animate({marginLeft : - scope.liWidth * scope.index + "px"},500); } }
scope.onClickRight = function(){
if(scope.index <= angular.element(".total_top ul li").length - 1 && scope.index > 0){
scope.index --;
angular.element(".total_top ul").stop().animate({marginLeft : - scope.liWidth * scope.index + "px"},500); }
}
}
}
})
</script>
</html>

一个简单的指令练习,主要实现的功能是点击事件,内容滚动。

点击左右的方框箭头,可以使内容滚动,或者点击中间的小长方形条,也可以使得内容滚动起来。

如下图是界面显示效果  

对于指令中的作用域 “”=“”:表示与父scope中的属性进行双向数据绑定

对于指令中的作用域 “”&“”:表示与父scope中的函数进行传递,稍后进行调用

对于指令中的作用域 “”@“”:表示把当前属性作为字符串传递实现指令与html页面元素关联

angular指令的简单练习的更多相关文章

  1. angular指令浅谈

    今天在闲暇时间再次对angularjs的指令进行了初探,不探不知道一探吓一跳啊, 就一个简单的指令整整难住我了两个小时,先不说代码的逻辑是否复杂,就一些内部的一些实现让我看起来都是头疼的不行啊,不过最 ...

  2. angular指令

    转自:http://www.cnblogs.com/rohelm/p/4051437.html 对于指令,可以把它简单的理解成在特定DOM元素上运行的函数,指令可以扩展这个元素的功能. 首先来看个完整 ...

  3. Angular4 后台管理系统搭建(9) - 用自定义angular指令,实现在服务端验证

    最近这段时间发现,北京这用angular4 或 angular2的公司很少.几乎是没有.很担心自己是不是把精力放到了不应该的地方.白耽误了时间.但是随着我对新版angular框架理解的加深.个人感觉a ...

  4. angular指令之complie和link不得不说的故事

    angular指令比较晦涩难懂的就是complie和link字段了,什么时候该用complie?什么时候该用link?总是很难分别清楚.当理解了指令的真正编译原理的时候,就会发现这相当的简单. ng怎 ...

  5. angular指令深度学习篇

    angular指令深度学习-过滤器 limitTo ... <body ng-app="app" > <div ng-controller="myCtr ...

  6. Angular指令渗透式理解

    通过一段时间对angular指令的使用,理解了angular指令的意义,下面逐一介绍一下. ng-app:定义一个angualr模块,表示angular作用的范围,如下代码: ng-app在html标 ...

  7. 20155219--pwd指令的简单实现

    pwd指令的简单实现 pwd命令作用 Linux中用** pwd **命令来查看"当前工作目录"的完整路径. 简单得说,每当你在终端进行操作时,你都会有一个当前工作目录. 在不太确 ...

  8. 【转】angular指令入坑

    独立作用域和函数参数 通过使用本地作用域属性,你可以传递一个外部的函数参数(如定义在控制器$scope中的函数)到指令.这些使用&就可以完成.下面是一个例子,定义一个叫做add的本地作用域属性 ...

  9. Angular指令1

    Angular的指令 也就是directive,其实就是一WebComponent,以前端的眼光来看,好象很复杂,但是以后端的眼光来看,还是非常简单的.其实就是一个中等水平的类. var myModu ...

随机推荐

  1. Github Page--CSDN新人的第二选择

    我也是个CSDN新人,使用的CSDN的初衷应该和众人类似,就是想总结下平时的学习成果,或者一些想法. CSDN好的地方: 书写界面简洁,支持markdown语法 人还算多,也比较年轻 相对较活跃 内容 ...

  2. 【源码】canal和otter的高可靠性分析

    一般来说,我们对于数据库最主要的要求就是:数据不丢.不管是主从复制,还是使用类似otter+canal这样的数据库同步方案,我们最基本的需求是,在数据不丢失的前提下,尽可能的保证系统的高可用,也就是在 ...

  3. 【转载】WAI-ARIA无障碍网页应用属性完全展示

    文章转载自 张鑫旭-鑫空间-鑫生活 http://www.zhangxinxu.com/wordpress/ 原文链接:http://www.zhangxinxu.com/wordpress/?p=2 ...

  4. 【特效】hover向上翻转效果

    前段时间做了很多有关css3动画的项目.虽然当时都较圆满的完成了,但事后还是要总结一下的,趁着近期工作不忙,系统的学习了一些动画理论,重点看了transform3D变换,学习了translate平移. ...

  5. Ubuntu Mac OS主题分享

    Ubuntu Mac OS主题分享 一直想搞一个Mac OS主题试试,结果很悲催,在网上搜索的Macbuntu主题在安装主题(macbuntu-os-themes-Its-v7)和 图标(macbun ...

  6. win10 3dmax 激活后反复激活和激活码无效问题

    我也是遇到这个问题在网上找答案,像什么断网,清理注册表,删除某个.dat文件 各种试了好多都没管用 弄这个弄了五六个小时才总算成功 心累 现在我总结一下这些方法  我是第一条成功的 其他的我试着都没用 ...

  7. win10 uwp MVVM 轻量框架

    如果在开发过程,遇到多个页面之间,需要传输信息,那么可能遇到设计的问题.如果因为一个页面内包含多个子页面和多个子页面之间的通信问题找不到一个好的解决方法,那么请看本文.如果因为ViewModel代码越 ...

  8. Java8系列之初识

    前言:终于有机会在工作中使用高版本的Java8,但是一直没有对java8中添加的新特性进一步了解过,所以趁着这个机会学习一下,能够在编程中熟练的使用. 一.接口的改变 我们知道,在java8版本以前, ...

  9. vue 父组件传递子组件事件

    在开发中,碰到一个需要从父组件传入方法,子组件点击触发,说白了就是,把方法传入给子组件调用 <el-col v-for='data in spreadFormat.icons' class=&q ...

  10. LeetCode 257. Binary Tree Paths (二叉树路径)

    Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 ...