Skip to content

Commit

Permalink
Fix scrolling issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Amr Abdulrahman committed Aug 2, 2015
1 parent 5821988 commit cb7b190
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
22 changes: 9 additions & 13 deletions demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
<h1>ng-tooltip demo</h1>
</div>
</div>




<table class="table table-striped">
<thead>
<tr>
Expand Down Expand Up @@ -70,7 +68,6 @@ <h1>ng-tooltip demo</h1>
<td></td>
</tr>


<!-- Positions -->
<tr>
<td>
Expand All @@ -85,15 +82,6 @@ <h1>ng-tooltip demo</h1>
Left
</tooltip>

<button id="btn-right" class="btn btn-info">Position:Right</button>
<tooltip
handle="btn-right"
on="hover"
position="right">
Right
</tooltip>


<button id="btn-top" class="btn btn-info">Position:Top</button>
<tooltip
handle="btn-top"
Expand All @@ -110,6 +98,14 @@ <h1>ng-tooltip demo</h1>
position="bottom">
Bottom
</tooltip>

<button id="btn-right" class="btn btn-info">Position:Right</button>
<tooltip
handle="btn-right"
on="hover"
position="right">
Right
</tooltip>
</td>
<td></td>
</tr>
Expand Down
43 changes: 26 additions & 17 deletions ng-tooltip.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
'use strict';

angular.module('ng-tooltip', [])
.directive('tooltip', function($templateCache, $timeout) {
$templateCache.put('ng-tooltip-template.html',
[
'<div ng-class="{animate: animate, open: visible}" class="smart-tooltip-wrapper"',
' style="top: {{top}}px; left:{{left}}px; -webkit-transition-duration: {{animateTime}}ms; transition-duration: {{animateTime}}ms;">',
' <div class="tooltip-content {{cssClass}}" style="border-color: {{borderColor}}; border-width: {{borderWidth}};">',
' <div ng-transclude></div>',
' <div ng-if="arrow" class="arrow" ng-class="{',
' up: position === \'bottom\',',
' down: position === \'top\',',
' left: position === \'right\',',
' right: position === \'left\'}"',
' style="border-color: {{borderColor}}; border-width: {{borderWidth}}; ',
' top: {{arrowTopOffset}}; left: {{arrowLeftOffset}}; width: {{arrowSize}}px; height: {{arrowSize}}px;',
' top: {{arrowTop}}px;"></div>',
' </div>',
'</div>'].join('')
.directive('tooltip', function ($templateCache, $timeout, $window) {
$templateCache.put('ng-tooltip-template.html', [
'<div ng-class="{animate: animate, open: visible}" class="smart-tooltip-wrapper"',
' style="top: {{top}}px; left:{{left}}px; -webkit-transition-duration: {{animateTime}}ms; transition-duration: {{animateTime}}ms;">',
' <div class="tooltip-content {{cssClass}}" style="border-color: {{borderColor}}; border-width: {{borderWidth}};">',
' <div ng-transclude></div>',
' <div ng-if="arrow" class="arrow" ng-class="{',
' up: position === \'bottom\',',
' down: position === \'top\',',
' left: position === \'right\',',
' right: position === \'left\'}"',
' style="border-color: {{borderColor}}; border-width: {{borderWidth}}; ',
' top: {{arrowTopOffset}}; left: {{arrowLeftOffset}}; width: {{arrowSize}}px; height: {{arrowSize}}px;',
' top: {{arrowTop}}px;"></div>',
' </div>',
'</div>'].join('')
);

return {
Expand Down Expand Up @@ -114,6 +113,9 @@ angular.module('ng-tooltip', [])
scope.left = eLeft - contentWidth - arrowSize;
}

scope.top -= $(window).scrollTop();
scope.left -= $(window).scrollLeft();

scope.$apply(function () {
scope.visible = true;
});
Expand Down Expand Up @@ -163,6 +165,13 @@ angular.module('ng-tooltip', [])
$timeout(show, 0);
}
});

// watch scroll
angular.element($window).bind('scroll', function() {
if(scope.visible === true) {
$timeout(show, 0);
}
});
}

$timeout(load, 0);
Expand Down

0 comments on commit cb7b190

Please sign in to comment.