我正在建立一个网站,并有一个带有框的内容区域来显示公司服务。在我的导航栏中,我有一个名为“联系人”的按钮。单击“联系人”后,将隐藏内容区域并显示联系人div。这适用于Chrome和FF,但是IE它是一个很大的混乱。下面是一些代码。
联系区域的HTML代码:
<div class="contact">
<h2>Contact Us</h2>
<p>For emergencies or to arrange a quote, call <span style="font-weight:bold; color:red;">999</span>. Or use the form below and we'll get back to you shortly.</p>
<form class="tab">
<label for="move">Your Name:</label>
<input type="text" name="move" class="move" /><br />
<label for="locate">Your Email:</label>
<input type="text" name="locate" class="locate" /><br /> >
<label for="contact"> </label>
<a href='#contact' class='contact-submit'>Send!</a><a href="#" class="prepend-1 contact-close">Cancel</a><br />
</form>
</div>
内容区域的HTML代码:
<div class="content">
<div class="span-24 last">
<p></p>
</div>
<div class="span-6 append-1">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce viverra malesuada orci et lacinia. Ut ac augue diam. Fusce vitae felis velit, vitae vulputate libero. Pellentesque in nibh est, tincidunt ullamcorper dolor. Etiam condimentum semper sem a mollis. Cras faucibus, neque vitae egestas imperdiet, tellus lorem rutrum massa, eget ultrices libero purus quis mi. Aliquam erat volutpat. Donec non metus id sapien pulvinar consequat. Praesent ut lectus massa, id viverra orci. In hac habitasse platea dictumst.</p>
</div> <!-- END span-6 DIV -->
<div class="span-15 append-2 last prepend-bottom box2" style="overflow:hidden;">
<p>Cras viverra placerat luctus. Cras eu elit sit amet lectus pretium egestas id a est. Mauris pretium lacus non eros dapibus at tempus leo condimentum. Quisque a elit non massa mattis pretium vitae eu est. Curabitur vulputate iaculis tellus tincidunt bibendum. Aliquam erat volutpat. Aenean nec viverra augue. Duis ultrices velit sed sapien suscipit eget dictum dolor feugiat. Aliquam erat volutpat. Nulla cursus dolor ut turpis congue sollicitudin. In hac habitasse platea dictumst. Duis facilisis malesuada magna, sed porttitor tortor posuere sed.</p>
</div> <!-- END span-6 DIV -->
<div class="prepend-3 boxes prepend-top">
<div class="clearfix row">
<div class="module compact clearfix">
<h4><a href="electrical/">Electrical</a></h4>
<div class="compact-content">
<img src="assets/images/electrical-image1.jpg" alt="" >
<p>We also offer electrical installations and maintenance for both commercial and domestic.</p>
</div> <!-- END compact-content DIV -->
</div> <!-- END module DIV -->
<div class="module compact clearfix">
<h4><a href="plumbing/">Plumbing</a></h4>
<div class="compact-content">
<img src="assets/images/plumbing-image1.jpg" alt="Property Maintenance and Refurbishment" >
<p>We offer plumbing for the commercial industry, no matter if it's big or a small job.<br /></p>
</div> <!-- END compact-content DIV -->
</div> <!-- END module DIV -->
<div class="module compact clearfix">
<h4><a href="security/">Security</a></h4>
<div class="compact-content">
<img src="assets/images/security-image1.jpg" alt="Security" >
<p>Security is key, that's why we are experts in the security field.</p>
</div> <!-- END compact-content DIV -->
</div> <!-- END module DIV -->
</div><!-- END clearfix row -->
</div><!-- END prepend-3 DIV -->
</div><!-- END content DIV -->
jQuery代码:
$('a.contact-close').click(function(){//If cancel has been clicked, show original content.
$('div.contact').hide('slow', function(){
$('div.content').show('slow', function(){
$('div.boxes').show('slow').delay(700);
});//END div.content show-slow
});
});
//Below is the contact script
$('div.contact').hide();//Hide div
$('div.nav a.contact').click(function(){//If Contact has been clicked show Contact div
$('div.boxes').hide('slow', function(){
$('div.content').hide('slow', function(){
$('div.contact').show('slow');
});
});//END Boxes hide
});
这个的CSS是在jsFiddle: http://jsfiddle.net/hart1994/Nh9tP/
在Internet Explorer中,它会在隐藏过程中跳转框。然后当重新显示时,它会错误地将它们放在两行而不是三行中。请参阅以下网站链接以获取完整演示。
您可能需要重建它,因为它可能不会在jsFiddle中显示。
或者你可以看看: http://molossi.psm2.co.uk/
我已经尝试将jQuery更改为slideDown / Up和fadeOut / In。
提前致谢!
答案 0 :(得分:2)
jQuery hide()
和show()
方法“同时为匹配元素的宽度,高度和不透明度设置动画”,以便高度和宽度发生变化时,浏览器会重新流动文档。浏览器确实以非常不同的方式重新流动,而在IE中,这使得盒子跳跃。您可能想要使用自定义jQuery animate()
- 也许只是高度?正在减少 width 会导致浮动元素重新流动。
选择“取消”链接后损坏的布局是由动画后jQuery在style
上留下<div class="boxes">
引起的。这导致 box div 无法正确清除左侧的段落,因此宽度较小,因此不能在行上放置3个子元素。您可以通过挂钩最终show()方法的回调来删除jQuery离开这些额外的样式,如下所示:
$('div.boxes').show('slow', function() {
$(this).attr('style', '');
}).delay(700);
还要注意,它可能无助于IE将在quirks mode中运行。您的页面没有doctype,根据我的经验,这可能导致不必要的和意外的渲染问题(特别是在IE中)。除了缺少的doctype之外,还有一些其他小问题导致您将页面转到not validate。
希望这很有用: - )