Saturday, May 28, 2016

Set postition of Search Hover Panel in Search Result Page

In the search result page in sharepoint 2013 while i hover on the search result the search hover panel puts a vertical scroll bar on the page.

There is a javascript written in sharepoint which sets the top, left and other attributes for search hover panel during the mose hover.

To set the top and left attribute for search hover panel i need something which overwrites the top and left atrribute for the search hover panel which has been set by the sharepoint.

for this i wrote my script under Window.load to make sure my code overwrites the attribute which has been set by Sharepoint.


$('.ms-srch-item').hover(function (evt) {
var div = evt.target;
var top = (getOffset(document.getElementById(div.id)).top + 50) + "px";
$('.ms-srch-hover-outerContainer').css("top", top);
$('.ms-srch-hover-outerContainer').css("left", $("#"+ div.id).width() + "px");
$('.ms-srch-hover-outerContainer').css("widht", $("#"+ div.id).width() + "px");
//alert("Top : " + top + ", Width : " + $("#"+ div.id).width());
}, function () {
$('.ms-srch-hover-outerContainer').css("visibility", "hidden");
});

function getOffset(el) {
var _x = 0;
var _y = 0;
while (el && !isNaN(el.offsetLeft) && !isNaN(el.offsetTop)) {
_x += el.offsetLeft - el.scrollLeft;
_y += el.offsetTop - el.scrollTop;
el = el.offsetParent;
}
return { top: _y, left: _x };
}

No comments:

Post a Comment