【发布时间】:2014-03-04 20:05:56
【问题描述】:
我需要在一个-responsive-图像上添加一个类似“video”的字符串,这也是他的alt标签。 例如:
<img src="my_image" alt="VIDEO">
我应该有我的图像,并在中心(垂直和水平)使用字符串“VIDEO”作为替代。 我不知道如何使用 jquery,我已经搜索了很多,但没有什么是我真正需要的。
看到我不需要 CSS 解决方案!
我有我的理由,但我需要 jquery 解决方案。我试过了,但没有... 如果我写:
<script>
$(function () {
var info = $("#informa");
if (info.length == 0) {
info = $("<span />").addClass("informa");
$("body").append(info);
}
info.hide();
$(".hover_text").bind("mouseenter", function () {
var p = GetScreenCordinates(this);
info.html(this.alt);
info.show();
info.css("width", $(this).width());
info.css({ "left": p.x, "top": p.y + this.offsetHeight - info[0].offsetHeight });
});
$(".hover_text").bind("mouseleave", function () {
info.hide();
});
});
function GetScreenCordinates(obj) {
var p = {};
p.x = obj.offsetLeft;
p.y = obj.offsetTop;
while (obj.offsetParent) {
p.x = p.x + obj.offsetParent.offsetLeft;
p.y = p.y + obj.offsetParent.offsetTop;
if (obj == document.getElementsByTagName("body")[0]) {
break;
}
else {
obj = obj.offsetParent;
}
}
return p;
}
</script>
我的图片是:
<img src="myimage.jpg" class="hover_text" alt="Collection">
它看起来是正确的,但在顶部。
【问题讨论】: