angular.directive('dblScroll', dblScroll)

dblSroll.$inject = [
'$timeout'
];
function dblScroll($timeout) {
return {
restrict: 'A',
transclude: true,
scope: {
dblScroll: '<'
},
template: `
<div >
<div class="dblscroll__div--wrapper"
ng-hide="!dblScroll"
ng-style="outterStyle"
style="height: 20px; position: absolute; left: 0; right: 0; top: -20px; overflow-y: hidden; overflow-x: auto;" >
<div class="dblscroll__div--inner" ng-style="innerStyle">&nbsp;</div>
</div>
<div ng-transclude></div>
</div>
`,
link: function (scope, el) { function selectParent() {
const dom = document.querySelector('[dbl-scroll-container]');
if (dom) {
return dom;
}
return el.parent()[0];
} let wLsn, winLsn, tLsn;
let firstTime = null;
const table = el[0];
const target = selectParent(); if (scope.dblScroll) {
const wrapper = document.querySelector('.dblscroll__div--wrapper'); const targetScrollHandler = () => {
wrapper.scrollLeft = target.scrollLeft
};
const wrapperScrollHandler = () => {
target.scrollLeft = wrapper.scrollLeft
};
const windowResizeHandler = () => {
$timeout(() => {
update();
}, 66)
}; tLsn = target.addEventListener('scroll', targetScrollHandler);
wLsn = wrapper.addEventListener('scroll', wrapperScrollHandler);
winLsn = window.addEventListener('resize', windowResizeHandler); const update = () => {
const scrollWidth = table.scrollWidth;
const clientWidth = target.clientWidth;
scope.innerStyle = {width: scrollWidth + 'px'};
scope.outterStyle = {width: clientWidth + 'px'};
}; scope.$watch(() => {
if (!firstTime) {
firstTime = target.scrollWidth + target.clientWidth;
}
return target.scrollWidth + target.clientWidth - firstTime;
}, () => {
$timeout(() => {
update();
}, 66)
}); scope.$on('$destroy', function(){
if (tLsn) {
tLsn.removeEventListener('scroll', targetScrollHandler);
}
if (wLsn) {
wLsn.removeEventListener('scroll', wrapperScrollHandler);
}
if(winLsn) {
winLsn.removeEventListener('resize', windowResizeHandler);
}
});
}
}
}
} export default dblScroll;

Using it:

  <div style="position: relative;" >
<div style="width: 300px; height: auto; overflow-x: auto;" >
<div style="width: 600px; height: 300px;" dbl-scroll=true>div</div>
</div>
</div>

[AngularJS] Directive for top scroll bar的更多相关文章

  1. [译]angularjs directive design made easy

    原文: http://seanhess.github.io/2013/10/14/angularjs-directive-design.html AngularJS directives很酷 Angu ...

  2. Selenium - IWebDriver 控制scroll bar到底部

    有时候我们需要控制页面滚动条上的滚动条,但滚动条并非页面上的元素,这个时候就需要借助js是来进行操作.一般用到操作滚动条的会两个场景: 注册时的法律条文需要阅读,判断用户是否阅读的标准是:滚动条是否拉 ...

  3. 学习AngularJs:Directive指令用法

    跟我学AngularJs:Directive指令用法解读(上) http://blog.csdn.net/evankaka/article/details/51232895 跟我学AngularJs: ...

  4. angularjs directive 实例 详解

    前面提到了angularjs的factory,service,provider,这个可以理解成php的model,这种model是不带html的,今天所说的directive,也可以理解成php的mo ...

  5. Android - 隐藏最顶端的通知条(Top Notification Bar)

    隐藏最顶端的通知条(Top Notification Bar/ActionBar) 本文地址: http://blog.csdn.net/caroline_wendy Android中, 视频播放等功 ...

  6. 学习AngularJs:Directive指令用法(完整版)

    这篇文章主要学习AngularJs:Directive指令用法,内容很全面,感兴趣的小伙伴们可以参考一下   本教程使用AngularJs版本:1.5.3 AngularJs GitHub: http ...

  7. Angularjs directive全面解读(1.4.5)

    说到Angularjs directive即指令,可以这么说Angularjs的灵魂就是指令,学会Angularjs指令那么你的Angularjs的武功就修炼了一半了,当然这只是鄙人的一点点独到见解, ...

  8. angularjs directive (自定义标签解析)

    angularjs directive (自定义标签解析) 定义tpl <!-- 注意要有根标签 --> <div class="list list-inset" ...

  9. VS2010/MFC编程入门之二十六(常用控件:滚动条控件Scroll Bar)

    回顾上一节,鸡啄米讲的是组合框控件Combo Box的使用.本节详解滚动条控件Scroll Bar的相关内容. 滚动条控件简介 滚动条大家也很熟悉了,Windows窗口中很多都有滚动条.前面讲的列表框 ...

随机推荐

  1. 洛谷 P1506 拯救oibh总部

    P1506 拯救oibh总部 题目背景 oibh总部突然被水淹没了!现在需要你的救援…… 题目描述 oibh被突来的洪水淹没了>.<还好oibh总部有在某些重要的地方起一些围墙,用*号表示 ...

  2. 洛谷 P3505 [POI2010]TEL-Teleportation

    P3505 [POI2010]TEL-Teleportation 题目描述 King Byteasar is the ruler of the whole solar system that cont ...

  3. EasyUI——DataGrid中嵌入Radio

    前一篇博客写到项目中的广告位管理,当时没有写到今天的问题,这个问题当时也是困扰我好久. 经过自己的努力和同志们的帮助,最后最终解决. 实现要求把全部的广告位后面的单选button设成一组,目的是一个广 ...

  4. apache2 虚拟机多用户多站点设置 mpm-itk

    MPM设置 https://bbs.csdn.net/topics/390479795/ vim /opt/lampp/etc/extra/httpd-ssl.conf vim /opt/lampp/ ...

  5. jquery init 关系

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/st ...

  6. Five ways to maximize Java NIO and NIO.2--转

    原文地址:http://www.javaworld.com/article/2078654/java-se/java-se-five-ways-to-maximize-java-nio-and-nio ...

  7. Day4晚笔记

    数据结构 并查集:捆绑两个点的信息,判断对错 倍增:LCA, 字符串 hash,模拟, 最小表示法 给定一个环状字符串,切开,使得字符串的字典序最小 图和树 割点,割边,强联通分量 点双联通分量 (把 ...

  8. 洛谷 P1208 [USACO1.3]混合牛奶 Mixing Milk

    P1208 [USACO1.3]混合牛奶 Mixing Milk 题目描述 由于乳制品产业利润很低,所以降低原材料(牛奶)价格就变得十分重要.帮助Marry乳业找到最优的牛奶采购方案. Marry乳业 ...

  9. Java经典23种设计模式之行为型模式(二)

    本文接着介绍行为型模式里的解释器模式.迭代器模式.中介者模式. 一.解释器模式Interpret 给定一个语言,定义它的文法的一种表示,并定义一个解释器,这个解释器使用该表示来解释语言的中的句子. 1 ...

  10. ajax中的POST和GET传值

    ajax中的POST和GET传值 转自:http://www.cnblogs.com/jtome/archive/2008/12/04/1347864.html Ajax中我们经常用到get和post ...