I copied the code from jsfiddle which works in fiddler but when I try to run the same code in my browser, I do not get the scroll event. there are no errors in the console. Here is the code which I copied from jsfiddle.
HTML file
<!DOCTYPE html>
<html>
<head>
<title>Angular Synchronous scroll</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular.min.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="script.js"></script>
</head>
<body ng-app="myApp">
<div class="wrapper" combine-horizontal-scrolls="horizontal-scroll">
<div class="horizontal-scroll top"><div class="content"></div></div>
<div class="horizontal-scroll bottom"><div class="content"></div></div>
</div>
</body>
</html>
JS file
var myApp = angular.module('myApp',[]);
myApp.directive('combineHorizontalScrolls', [function(){
var scrollTop = 0;
function combine(elements){
elements.on('scroll', function(e){
if(e.isTrigger){
debugger;
e.target.scrollTop = scrollTop;
}else {
scrollTop = e.target.scrollTop;
elements.each(function (element) {
if( !this.isSameNode(e.target) ){
$(this).trigger('scroll');
}
});
}
});
}
return {
restrict: 'A',
replace: false,
compile: function(element, attrs){
combine(element.find('.'+attrs.combineHorizontalScrolls));
}
};
}]);
CSS file
.top{
background: yellow;
height: 100px;
overflow-x: auto;
}
.bottom{
background: red;
height: 100px;
overflow-x: auto;
}
.content{
width: 300%;
height: 100%;
}