新手 - ie7 和 jquery .animate() - 滑动字幕
我正在尝试制作一些滑动字幕,例如 马赛克,但更轻。在所有主流浏览器中一切看起来都很好(即使在 ie8 中看起来很慢),但在 ie7 中什么也没有发生。 我正在使用 ieTester 进行测试,我不知道该错误是否来自软件或来自我的代码。 我相信您会提供一些建议来帮助我改进它!
不管怎样,谢谢。
HTML:
<div class="imgbox">
<img src="#" />
<a href="#" class="caption">
<div class="details">
<h6>Lorem ipsum</h6>
<p>Lorem ipsum dolor sit amet,…</p>
</div>
</a>
</div>
CSS:
.imgbox{
width: 204px;
height: 154px;
position: relative;
overflow: hidden;
float: left;
margin: 10px;
border:1px solid #999;
-webkit-box-shadow:0 1px 3px rgba(0,0,0,0.8);
-moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);}
.imgbox img{
width: 200px;
height: 150px;
padding: 2px;
overflow: hidden;}
.caption{
display:block;
position:absolute;
top:104px;
height:100%;
width:100%;
background: rgb(0,0,0);
background: rgba(0,0,0,0.6);
background: transparent\9;
zoom: 1;
-ms-filter:"progid:DXImageTransform.Microsoft.gradient(startColorstr=#99000000, endColorstr=#99000000)"; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#99000000, endColorstr=#99000000);}
JS:
$(".imgbox").hover(
function()
{$(this).children('.caption').animate({top:0},"fast");},
function()
{$(this).children('.caption').animate({top:104},"fast");}
);
I'm trying to make some sliding captions, something like Mosaic, but lighter. Everything looks good in all major browsers (even if it looks slow in ie8), but nothing happens in ie7.
I'm testing with ieTester, and I have no idea if the bug comes from the software or from my code.
I'm sure you'll have some tips to help me improve it!
Thanks anyway.
HTML:
<div class="imgbox">
<img src="#" />
<a href="#" class="caption">
<div class="details">
<h6>Lorem ipsum</h6>
<p>Lorem ipsum dolor sit amet,…</p>
</div>
</a>
</div>
CSS:
.imgbox{
width: 204px;
height: 154px;
position: relative;
overflow: hidden;
float: left;
margin: 10px;
border:1px solid #999;
-webkit-box-shadow:0 1px 3px rgba(0,0,0,0.8);
-moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);}
.imgbox img{
width: 200px;
height: 150px;
padding: 2px;
overflow: hidden;}
.caption{
display:block;
position:absolute;
top:104px;
height:100%;
width:100%;
background: rgb(0,0,0);
background: rgba(0,0,0,0.6);
background: transparent\9;
zoom: 1;
-ms-filter:"progid:DXImageTransform.Microsoft.gradient(startColorstr=#99000000, endColorstr=#99000000)"; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#99000000, endColorstr=#99000000);}
JS:
$(".imgbox").hover(
function()
{$(this).children('.caption').animate({top:0},"fast");},
function()
{$(this).children('.caption').animate({top:104},"fast");}
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的 HTML 代码无效。
a
元素是内联元素,它不能包含像div
这样的块元素。浏览器有不同的方式来处理不正确的标记,并且可能会重新排列或忽略某些标记以创建有效的元素。将内联元素放入链接内,以便正确解析它们,然后您可以使用 CSS 将它们转换为块元素:
CSS:
CSS 代码中还有一些 hack,可能并不适合 IE7。您可以注释掉其中一些以测试它们是否会导致问题。
Your HTML code is invalid. The
a
element is an inline element, and it can't contain block elements likediv
. Browsers have different ways of dealing with incorrect markup, and might rearrange or ignore certain tags to create elements that are valid.Put inline elements inside the link so that they are parsed correctly, then you can use CSS to turn them into block elements:
CSS:
There are also some hacks in the CSS code that might not all go down well with IE7. You can comment out some of them to test if they cause problems.
我发现它来自标题的位置。我设置了顶部位置,但没有定义任何左侧或右侧位置。
有了这段代码,它现在出现在 ie7 上:
但在 ie8 和 ie7 上仍然很慢。
不管怎样,问题解决了!
I found that it came from the position of the caption. I set a top position but didn't define any left or right position.
With that piece of code it now appears on ie7:
But it's still very slow on ie8 and ie7.
Anyway, problem solved!