动画宽度在 chrome 和 safari 中无法正常工作
我在使用此脚本时遇到 safari 和 chrome 浏览器问题。我可以在两个浏览器中关闭侧边栏,但是当我单击将其滑动打开时,侧边栏会打开透明。一切正常,并且在 ff、opera 和 ie7+ 中都应该正常工作,
有什么想法吗?
<!doctype html>
<html lang="et">
<head>
<meta charset="utf-8">
<title>Test</title>
<script src="jquery-1.7.1.min.js"></script>
<style>
body, html {
margin:0;
background-color:#666;
}
.fixed {
position:fixed;
width:auto;
height:100%;
}
.sidebar {
float:left;
width:300px;
height:100%;
}
.header {
float:left;
width:300px;
height:1200px;
background-color:#d8d8d8;
}
.body {
margin-left:600px;
width:600px;
background-color:red;
height:2000px;
}
</style>
<script>
$(document).ready(function() {
/*$('.sidebar').addClass('closed');
$('.sidebar').hide();
$('.body').css('margin-left', 300);*/
$('.close').click(function(e) {
e.preventDefault();
if($('.sidebar').hasClass('closed')) {
$('.sidebar').animate({ width : 'show'});
$('.body').animate({ marginLeft : 600});
$('.sidebar').removeClass('closed');
} else {
$('.sidebar').animate({ width : 'hide'});
$('.body').animate({ marginLeft : 300});
$('.sidebar').addClass('closed');
}
});
});
</script>
</head>
<body>
<div class="fixed">
<div class="sidebar">sidebar</div>
<div class="header"><a href="#" class="close">sule</a></div>
</div>
<div class="body">body</div>
</body>
</html>
i have a problem with safari and chrome browser with this script. i can close sidebar in both browsers, but when i click to slide it open, sidebar opens transparent. everything works correctly and as it should in ff, opera and ie7+
any ideas?
<!doctype html>
<html lang="et">
<head>
<meta charset="utf-8">
<title>Test</title>
<script src="jquery-1.7.1.min.js"></script>
<style>
body, html {
margin:0;
background-color:#666;
}
.fixed {
position:fixed;
width:auto;
height:100%;
}
.sidebar {
float:left;
width:300px;
height:100%;
}
.header {
float:left;
width:300px;
height:1200px;
background-color:#d8d8d8;
}
.body {
margin-left:600px;
width:600px;
background-color:red;
height:2000px;
}
</style>
<script>
$(document).ready(function() {
/*$('.sidebar').addClass('closed');
$('.sidebar').hide();
$('.body').css('margin-left', 300);*/
$('.close').click(function(e) {
e.preventDefault();
if($('.sidebar').hasClass('closed')) {
$('.sidebar').animate({ width : 'show'});
$('.body').animate({ marginLeft : 600});
$('.sidebar').removeClass('closed');
} else {
$('.sidebar').animate({ width : 'hide'});
$('.body').animate({ marginLeft : 300});
$('.sidebar').addClass('closed');
}
});
});
</script>
</head>
<body>
<div class="fixed">
<div class="sidebar">sidebar</div>
<div class="header"><a href="#" class="close">sule</a></div>
</div>
<div class="body">body</div>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更新
正如评论中提到的。您可以使用此版本 http://jsfiddle.net/QqGk6/ 来解决您的问题
较少 hacky,但是更详细。看起来这是一个常见的 WebKit 问题。
我发现这篇文章很有趣: http://ajaxian.com/archives/ forcing-a-ui-redraw-from-javascript
您也可以尝试“add/removeClass”方法。
似乎他们不想重新绘制您的 .header .. 可能有点 hacky,但您可以检查一下
希望这会帮助您找到问题。
Update
As mentioned in the comment. You can use this version http://jsfiddle.net/QqGk6/ to solve your problem
Less hacky, but more verbose. Seems like this is a common WebKit Problem.
I found this article interesting: http://ajaxian.com/archives/forcing-a-ui-redraw-from-javascript
You could also try the "add/removeClass" method.
Seems like they dont want to repaint your .header .. Probably a bit hacky, but you can check this with
Hope this will help you find the Problem.
好的。我实际上重构了你的标记和 CSS。在这种情况下,这就是您想要的。您真的需要固定包装吗?尝试流畅的布局:)
我将新的 html、css 和 js 发布到了 fiddle -> http://jsfiddle.net/QqGk6/
Ok. I actually refactored your markup and CSS. This is, in that case, what you want. Do you really need a fixed wrapper? Try fluid layouts :)
I posted the new html, css and js to fiddle -> http://jsfiddle.net/QqGk6/