如何在保持鼠标悬停功能的同时居中跨过图像
How to center span over image while maintaining mouseover functionality
<div class="pic">
<img src="image.jpg" height="250"/>
<span class="text" style="display:none">text here</span>
</div>
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
<script type="text/javascript">
$('img').css('opacity', 0.4);
$('img').next('span.text').show();
$('img').bind('mouseover', function () {
$(this).css('opacity', 1.0);
$(this).next('span.text').hide();
});
$('img').bind('mouseout', function () {
$(this).css('opacity', 0.3);
$(this).next('span.text').show();
});
</script>
我有一个不透明的图像,在mouseover
上完全可见。我添加了跨度的文本,这些文本将在mouseover
上消失,并在mouseout
上重新出现,类似于图像上的不透明性。我试图在 CSS 中用 margin-left:auto
和margin-right:auto
将文本居中,但缺乏结果。有没有办法使文本居中,同时仍然具有不透明度并且文本在mouseover
上消失?Javascript是最好的方法吗?
谢谢
你不能
用CSS做到这一点吗?
body {
text-align: center;
}
.pic {
display: inline-block;
margin: 25px;
border: 1px solid red;
position:relative;
}
.pic img {
display: block;
opacity: 0.4;
transition: opacity 0.5s ease;
}
.text {
opacity: 1;
position:absolute;
top:50%;
left:50%;
transform:translate(-50%,-50%);
transition: opacity 0.5s ease;
}
.pic:hover img {
opacity: 1;
}
.pic:hover .text {
opacity: 0;
}
<div class="pic">
<img src="http://lorempixel.com/output/city-q-c-250-250-7.jpg" />
<span class="text">text here</span>
</div>
相关文章:
- 为图像滑块jquery添加项目符号功能
- 使用JavaScript功能切换图像位置
- 单击水平滚动库中的图像以居中显示无法工作的功能
- AngularJS:为ng-repeat中的图像添加切换功能
- 如何在保持鼠标悬停功能的同时居中跨过图像
- 这个图像加载功能有什么作用
- 图像上传功能将++(+1)副本添加到下一次上传.出了什么问题或如何重置“选定图像”
- 将复选框转换为图像,需要添加拖动功能才能更改图像
- 本地存储功能中的图像不起作用
- 利用移动设备上的滑动功能浏览图像阵列
- jQuery预加载图像功能
- 点击时输入图像功能打开,再次点击功能关闭
- 单击时动画化图像功能,同时重叠其同级元素
- HTML5 画布绘制图像功能在源画布和目标画布相同时变慢
- 具有ajax的一次更改图像功能已经完成
- 禁用幻灯片放映插件中的居中图像功能
- 动态画布绘制图像功能
- 开发3D交互图像功能的方向是什么?
- 如何在Gmail和Google Chrome 12+中使用剪贴板粘贴图像功能
- 双击图像功能