我遇到了bootstrap popovers的问题。将鼠标悬停在元素上时,它会将您滚动到页面顶部。这就是我到目前为止所拥有的。我尝试添加一个preventDefault调用以避免滚动,我不确定还有什么可以尝试。非常感谢任何帮助:)
.directive( 'popover', ['$compile', function($compile) {
return {
restrict: 'E',
template: '<a href="#" bs-popover="popover" html="true" trigger="hover" student-name ng-click="popupStudentInfo(student.id);" class="student-name">{{student.full_name}}</a>',
replace: true,
link: function( scope, elem, attrs ) {
$(elem).on('mouseover', function(e) {e.preventDefault(); return true;});
scope.$watch('student', function() {
$(elem).on('mouseover', function(e) {e.preventDefault(); return true;});
var math_color = '';
if (scope.student.math_pass_rate > 80) {
math_color = 'green';
} else if (scope.student.math_pass_rate >= 51) {
math_color = 'orange';
} else {
math_color = 'red';
}
var lit_color = '';
if (scope.student.literacy_pass_rate > 80) {
lit_color = 'green';
} else if (scope.student.literacy_pass_rate >= 51) {
lit_color = 'orange';
} else {
lit_color = 'red';
}
scope.popover = {
"title": "<i class='beta icon-book left'></i><div>" +
"Level " + scope.student.v1_student.math_level + "<br>" +
"<span class='" + math_color + "'>" + Math.round(scope.student.math_pass_rate) + " % Pass Rate" + "</span><br>" +
scope.student.math_completed + " Passed / " + (scope.student.math_attempted + scope.student.math_completed) + " Attempted</div>" +
"<i class='beta icon-calculate left'></i><div> Level " + scope.student.v1_student.literacy_level + "<br><span class='" + lit_color + "'>" + Math.round(scope.student.literacy_pass_rate) + " % Pass Rate</span><br>" +
scope.student.literacy_completed + " Passed / " + (scope.student.literacy_attempted + scope.student.literacy_completed) + " Attempted</div>"
,
"content": "<span></span>",
"html": true
};
}, true)
}
}
}])