I've got 3 divs using JQuery's toggle function to collapse divs:
The divs collapse fine in Firefox, but in IE6 (target browser), this happens:
If I resize the IE window, the divs go back to looking normal, as they do in Firefox.
I've tried to get the code down to its simplest form:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>BIIS Portal</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="pragma" content="cache" />
<link rel="stylesheet" type="text/css" media="all" href="../assets/stylesheets/core-css.css" /&g开发者_开发知识库t;
<script type="text/javascript" src="../assets/js/core-js.js"></script>
<!-- This script doesn't seem to work when put it in its own .js file... why? -->
<script type="text/javascript">
$(document).ready(function(){
//Hide (collapse) the toggle containers on load
$(".toggle-container").hide();
//Show all containers with class toggle-opened
//Remove the opened class
//Find the trigger for the now opened container and apply the active class
$(".toggle-opened").show().removeClass("toggle-opened").prev(".toggle-trigger").addClass("active");
//Switch the Open and Close state per click then slide up/down (depending on open/close state)
$(".toggle-trigger").click(function(){
$(this).toggleClass("active").next().toggle();
return false; //Prevent the browser jump to the link anchor
});
});
</script>
</head>
<body>
<div id="wrapper">
<div id="header">
</div>
<div id="body">
<div>
<div class="portlet">
<div class="portlet-header">
<div class="portlet-title">
<h2>BI - External data Control</h2>
</div>
</div>
<div class="portlet-body">
<div>
<h3 class="toggle-trigger">External Data Configuration</h3>
<div class="toggle-container toggle-opened">
blah
</div>
<h3 class="toggle-trigger">Current Notifications</h3>
<div class="toggle-container toggle-opened">
blah
</div>
<h3 class="toggle-trigger">General Information</h3>
<div class="toggle-container toggle-opened">
blah
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
core-css.css:
@import "base.css";
@import "framework.css";
@import "elastic.css";
@import "superfish.css";
@import "/application/css/jquery.autocomplete.css";
@import "/application/css/hspi-content-nav.css";
@import "/application/css/jquery-ui/jquery-ui-1.8.12.custom.css";
core-js.js is merely several JQuery libraries minified, namely:
- jQuery JavaScript Library v1.5.2
- jQuery Cycle Plugin (with Transition Definitions) Version: 2.86 (05-APR-2010)
- jQuery Cycle Plugin Transition Definitions Version: 2.72
- jQuery UI 1.8.12
- jQuery UI Widget 1.8.12
- jQuery UI Mouse 1.8.12
I'm not too sure what's happening, as I've mostly copied existing code. I need to get it working right in IE, so any advice is appreciated.
@Mitch. I think your main problem it's your CSS styles. You dont provide CSS code, but next example is worked in my tests in IE6-8 and FF7 (except that IE6-7 do not support CSS content
style) http://jsfiddle.net/2YyXC/
HTML:
<div id="wrapper">
<div id="header">
</div>
<div id="body">
<div>
<div class="portlet">
<div class="portlet-header">
<div class="portlet-title">
<h2>BI - External data Control</h2>
</div>
</div>
<div class="portlet-body">
<div>
<h3 class="toggle-trigger toggle-trigger-active">External Data Configuration</h3>
<div class="toggle-container toggle-container-opened">
blah
</div>
<h3 class="toggle-trigger toggle-trigger-active">Current Notifications</h3>
<div class="toggle-container toggle-container-opened">
blah
</div>
<h3 class="toggle-trigger toggle-trigger-active">General Information</h3>
<div class="toggle-container toggle-container-opened">
blah
</div>
</div>
</div>
</div>
</div>
</div>
</div>
SCRIPT:
$(document).ready(function() {
$(".toggle-trigger").click(function(){
$(this).toggleClass("toggle-trigger-active").next().toggleClass("toggle-container-opened");
return false; //Prevent the browser jump to the link anchor
});
});
CSS:
.portlet {
padding: 5px 5px 5px 5px;
border: 1px solid black;
}
.portlet-body {
padding: 5px 5px 5px 5px;
}
.portlet-title {
background-color: black;
color: white;
font-family: Verdana;
font-size: 13px;
padding: 6px 6px 6px 6px;
}
.toggle-trigger {
background-color: lightgrey;
color: black;
font-family: Verdana;
font-size: 13px;
padding: 6px 6px 6px 6px;
}
.toggle-trigger:before {
content: "► ";
}
.toggle-trigger-active:before {
content: "▼ ";
}
.toggle-container {
font-family: Verdana;
font-size: 13px;
padding: 6px 6px 6px 6px;
display: none;
}
.toggle-container-opened {
display: block;
}
add conditional comments for ie6 with .toggle-container and/or .toggle-closed (not sure if you're using that class) display:none
A common problem is that things simply aren't redrawn as they should be. If resizing the window or zooming the page work, it's a redraw error and as far as I know there's abolutely nothing you can do about it in code, other than trying to find some other way of coding it that works.
精彩评论