在图像顶部显示文本
Show text on top of image
目前我有一个像这样的图像映射
<img src="Floor1.jpg" alt="Floor1" usemap="#Floor1">
<map id="Floor1" name="Floor1">
<area shape="rect" name="Seat1" title="Seat1" coords="535,311,133,555" href="#" target="" />
<area shape="rect" name="Seat2" title="Seat2" coords="121,211,111,555" href="#" target="" />
</map>
随之而来的是一个名为Image Mapster的Jquery插件,它允许我将鼠标悬停在该区域上并显示工具提示。
我现在想做的是能够在这个网站上添加一个额外的图像,但我不必将鼠标悬停在地图区域上才能看到信息,它只会显示图像地图内的信息,而我根本没有将鼠标悬停在该区域上。我会在 Photoshop 中执行此操作,但对于图像,工具提示内的信息可以动态更改,这就是我不能这样做的原因。
https://i.stack.imgur.com/uaTCr.png
感谢您的帮助!
如果我
正确理解你的问题,你应该能够只用css和html来做到这一点。
.html:
<div class="container">
<p class="example">Example</p>
<img src="test">
</div>
.css:
.container{
position: relative;
}
.example{
position:absolute;
top: 45%;
}
> http://jsfiddle.net/2v5Lpxwh/2/
.HTML:
<div id="map">
<img src="http://placehold.it/600" width="600" height="600" alt="Floor1" usemap="#Floor1">
<div id="map_title"><span></span>
</div>
</div>
<map id="Floor1" name="Floor1">
<area shape="rect" name="Seat1" title="Seat1" coords="535,311,133,555" href="#" target="" />
<area shape="rect" name="Seat2" title="Seat2" coords="121,211,11,555" href="#" target="" />
</map>
.CSS:
#map {
position:relative
}
#map_title {
position:absolute;
border:3px solid red;
text-align:center;
display:none;
}
#map_title span {
position: relative;
top: 45%;
transform: translateY(-45%);
}
JQ:
$(function () {
// show title on mosue enter
$('area').mouseenter(function () {
// takes the coordinates
var title = $(this).attr('title');
var coor = $(this).attr('coords');
var coorA = coor.split(',');
var left = coorA[0];
var top = coorA[1];
var right = coorA[2];
var bottom = coorA[3];
// in order to properly calculate the height and width
// left position must be less than the right
if (left > right) {
var tmp = right;
right = left;
left = tmp;
}
// The same applies to top and bottom
if (top > bottom) {
var tmp = top;
top = bottom;
bottom = tmp;
}
// has an error / bug when the mouse moves upward seat2 map will not hide
// this works
top--;
// calculate the width and height of the rectangle
var width = right - left;
var height = bottom - top;
// sets the position, the sizes and text for title
// show the title
var $map_title = $('#map_title');
$map_title.find('span').text(title);
$map_title.css({
top: top + 'px',
left: left + 'px',
width: width,
height: height
}).show();
})
// hide title on mouse leave
$('#map_title').mouseleave(function () {
$(this).hide();
})
})
相关文章:
- 为什么在页面上单击的先前链接的文本显示在 AJAX 请求中
- JavaScript NaN错误,输入文本显示为NaN
- 关于socket.io实时文本显示的问题
- 如何使用javascript使文本显示在文本字段中
- 在它们之间切换时,jQuery 文本显示在活动文本下方
- 使用 ajax 乱码文本显示图像
- 带有文本显示js功能的图像映射 - 某些部分不显示
- 来自 Ajax 请求的文本显示不正确
- 如何使用 JavaScript 使文本显示
- 是否可以将元素内部的文本显示在 ::在 css 之前
- on更改文本框的文本显示在另一个文本框上
- 在文本显示在Scroll上之前在页面上隐藏文本的问题
- 使用带文本显示的Jquery切换文本
- 如何使文本显示速度变慢
- 如何将图片添加到点击计数器文本显示<图像><点击量>
- 文本显示有延迟
- 根据在另一个文本框中输入的文本显示文本框中的文本
- 如何从点击文本显示文件浏览器,并在悬停文本时将鼠标光标更改为指针
- 使文本显示为几行可点击的线条
- 如何使文本显示