我有大約500 - 1000行實體稱爲測試,其中每個實體都有組件。當用戶懸停在任何測試中時,這些組件需要顯示。在mouseover
上,我在一個div中顯示組件信息並將其隱藏在mouseout
上。我能夠做到這一點,硬編碼頂部和左側的位置。但是,我需要能夠將該div顯示在光標右側,間隔爲50到100像素。jQuery:在某些元素的懸停上顯示光標右側的div
我該如何更改我的代碼來做到這一點?
$(".test_row").mouseover(function (event) {
fillTestComponents(test, testId);
});
$(".test_row").mouseout(function (event) {
$("#testCompHolder").hide();
});
function fillTestComponents(test, testId) {
$.ajax({
type: 'GET',
url: "@Url.Action("GetTestComponents", "Templates", new { area = "Orders" })",
data: { testIdentifier: testId },
async: false,
success: function (data) {
var componentCount = data.length;
if (componentCount != 0) {
componentsHtml = "<p><u>" + test + "</u></p><ul>";
for (var i = 0; i < componentCount; i++) {
componentsHtml = componentsHtml + "<li>(" + data[i].TestIdentifier + ") " + data[i].Description + "</li>"
}
componentsHtml += "</ul>";
$('#testCompHolder').html(componentsHtml);
$("#testCompHolder").show();
}
else {
componentsHtml = "<p>No components exist for this test.</p>";
$("#testCompHolder").show();
}
},
error: function() {
alert('An error occurred while loading the results.');
}
});
}
HTML:
<div id="testCompHolder" style="display:none; padding: 4px; border: 2px black solid; background-color: #dddddd; position: fixed; top: 300px; left: 380px;">
pageX/pageY正在將div發送到屏幕下方,所以我使用了screenX/screenY來代替,這對我的情況非常合適。我從這裏得到這個信息:http://stackoverflow.com/q/9262741/1539782 – Animesh
偉大的Avinash。謝謝。 – Abhitalks