我的 jquery 动画可以在 FF 中运行,但不能在 IE 或 Chrome 中运行
我想要一个“选项卡”突出在页面右侧,单击时会滑入(从右侧)。 (并在第二次单击时再次滑出)。 我的代码在 Firefox 中运行良好,但在 IE 和 Chrome 中,它最初出现在正确的位置,但单击后 - 立即切换到页面左侧。
有人可以指导/帮助我让它跨浏览器工作吗 - 谢谢。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<div id="slider" style="position:fixed;width:340px;right:-300px;bottom:80px;z-index:999">
<div id="slideButton" style="position:relative;float:left;height:120px;width:40px;background:fuchsia;text-align:center;">S<br/>l<br/>i<br/>d<br/>e<br/>r<br/></div>
<div id="slideContent" style="position:relative;float:left;height:120px;width:300px;background:yellow;">
Slider text goes here <br/>(should slide in/out <br/>from right of page) </div>
</div>
<script type="text/javascript">
$('#slideButton').toggle(function() {
$('#slider').animate({
left: '-=200'
}, 1500, 'swing', function() {
// Animation complete. CALLBACK?
});
}, function() {
$('#slider').animate({
left: '+=200'
}, 1000, 'swing', function() {
// Animation complete. CALLBACK?
});
});
</script>
</body>
</html>
I want a 'tab' sticking out on the right of the page, that slides in (from the right) on click. (and slides out again on 2nd click).
My code works in Firefox fine, but in IE and chrome it initially appears in the correct place, but on click - immediately swops to the left of the page.
Can someone guide/help me please to get it to work cross browser - thanks.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<div id="slider" style="position:fixed;width:340px;right:-300px;bottom:80px;z-index:999">
<div id="slideButton" style="position:relative;float:left;height:120px;width:40px;background:fuchsia;text-align:center;">S<br/>l<br/>i<br/>d<br/>e<br/>r<br/></div>
<div id="slideContent" style="position:relative;float:left;height:120px;width:300px;background:yellow;">
Slider text goes here <br/>(should slide in/out <br/>from right of page) </div>
</div>
<script type="text/javascript">
$('#slideButton').toggle(function() {
$('#slider').animate({
left: '-=200'
}, 1500, 'swing', function() {
// Animation complete. CALLBACK?
});
}, function() {
$('#slider').animate({
left: '+=200'
}, 1000, 'swing', function() {
// Animation complete. CALLBACK?
});
});
</script>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那是因为你正在为 css
left
属性设置动画,我认为你的意思是为right
设置动画。看看这个fiddleThat's because you're animating the css
left
property, i think you meant to animate theright
instead. Take a look at this fiddle将左侧替换为右侧并交换 += 和 -=
在 Chrome 中对我有用
replace left with right and swap += and -=
works for me in Chrome