javascript - How to get the coordinate of element tag inside link function of angularJs directive -
javascript - How to get the coordinate of element tag inside link function of angularJs directive -
i implementing tool tip through directive in angularjs not able element coordinate. when tooltip visible want coordinate of position , want display according position.
'use strict'; var utility = angular.module("utility", []); utility.directive("tooltip", function () { var directive = {}; directive.restrict = 'a'; directive.transclude = true; directive.link = function ($scope, element, attributes) { element.html("this new content: "); element.bind('mouseenter', creatediv); element.bind('mouseleave', destroydiv); function creatediv() { //need coordinate of pointer display div on hover of attribute. var divtag = document.createelement("div"); var tooltiphtml; divtag.id = "divtooltip"; divtag.setattribute("align", "center"); //divtag.style.border = "1px solid #ccc"; divtag.style.zindex = "999"; divtag.style.position = "absolute" divtag.style.width = "200px"; divtag.style.height = "115px"; tooltiphtml = "<div style=\" opacity:0.8; border-bottom:15px solid #000; border-left:10px solid transparent;border-right:10px solid transparent;width:0;height:0; \"></div>" tooltiphtml += "<div style = \"background-color:black; opacity:0.8; border: 1px solid #f11; width:98%; height:95%; -webkit-border-radius:20px; position:relative;\">"; tooltiphtml += "<div style=\" width:96%; height:10px; margin-top:15px;\"> <div style=\" float:left; width:90%; height:9px;\"></div> <div style=\" float:left; width:10%\"> <img src=\"./img/close.png\" alt=\"html tutorial\"/> </div> </div>"; tooltiphtml += "<div style=\"float:left; width:150px;\"/> " + $scope.tooltipdata.message + "</div>"; tooltiphtml += "</div>"; divtag.innerhtml = tooltiphtml; element.append(divtag); } function destroydiv() { var divtag = document.getelementbyid("divtooltip"); divtag.remove(); } } directive.scope = true; homecoming directive; });
angular.element jquery compatible api.
if jquery library included in page uses jquery not dependency.
since first argument of event handler in jquery event object, need pass argument event handler function , can access coordinates.
function creatediv(event){ var pagex = event.pagex, pagey = event.pagey; /* existing code */ } you can utilize create , manipulate new elements .
var divtag = angular.element('<div>'); divtag.css({zindex:999, position:'absolute', width: 200, height: 115}); reference : angular.element docs
javascript jquery angularjs-directive
Comments
Post a Comment