gpt4 book ai didi

javascript - fadeToggle 动画宽度出现故障?

转载 作者:行者123 更新时间:2023-12-03 10:07:56 24 4
gpt4 key购买 nike

这是我尝试复制我拥有的代码。由于某种原因,代码在 jsfiddle 中完美运行,但在我自己的网站上出现故障。也许有人可以以某种方式找出问题所在。

http://jsfiddle.net/neowot/g0teoyrc/

就像我说的,它在 jsfiddle 中运行良好,但在我的实际网站中,单击按钮会使 Div2 立即消失,然后在开始淡入淡出动画之前立即再次出现。显然这看起来非常糟糕和奇怪。

有人知道可能会发生什么吗?

HTML

<body>
<section id="wrapper">
<div id="button">B</div>
<div id="Div1">Div1</div>
<div id="Div2">Div2</div>
</section>
</body>

CSS

#wrapper{
width:1000px;
margin-left:auto;
margin-right:auto;
}
#Div1{
height:400px;
width:1000px;
position:relative;
float:left;
background:blue;
}

#Div2{
height:400px;
width:380px;
position:absolute;
top:20;
background:green;
display:none;
margin-left:380px;
}

#button{
width:20px;
height:20px;
background:orange;
cursor:pointer;
}

JS

$('#button').click(function() {


$('#Div2').fadeToggle(300);

var toggleWidth = $("#Div1").width() == 380 ? "1000px" : "380px";
$('#Div1').animate( {'width': toggleWidth}, 300);


});

最佳答案

对我来说就像 fiddle

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery animate </title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">

</head>

<style>
#wrapper{
width:1000px;
margin-left:auto;
margin-right:auto;
}
#Div1{
height:400px;
width:1000px;
position:relative;
float:left;
background:blue;
}

#Div2{
height:400px;
width:380px;
position:absolute;
top:20;
background:green;
display:none;
margin-left:380px;
}

#button{
width:20px;
height:20px;
background:orange;
cursor:pointer;
}

</style>
<body>

<section id="wrapper">
<div id="button">B</div>
<div id="Div1">Div1</div>
<div id="Div2">Div2</div>
</section>

<script>
$(document).ready(function(){

$('#button').click(function() {


$('#Div2').fadeToggle(300);

var toggleWidth = $("#Div1").width() == 380 ? "1000px" : "380px";
$('#Div1').animate( {'width': toggleWidth}, 300);


});
});

</script>
</body>
</html>

关于javascript - fadeToggle 动画宽度出现故障?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30279641/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com