gpt4 book ai didi

javascript - 两个div之间的水平滑动效果与JQuery

转载 作者:太空宇宙 更新时间:2023-11-04 06:46:44 26 4
gpt4 key购买 nike

我有两个 div,我在它们之间使用了一个滑动效果,点击一个按钮,它看起来像这样:

function openNav() {
$(".lediv1").animate({
left: '-100%'
}, {
duration: 500,
start: function() {
$(".lediv2").show().animate({
left: '0%'
}, 500);
},
complete: function() {
$(".lediv1").css({
"display": "none"
});
}
});
}

function closeNav() {
$(".lediv2").animate({
left: '100%'
}, {
duration: 500,
start: function() {
$(".lediv1").animate({
left: '0%'
}, 500);
},
complete: function() {
$(".lediv1").show();
$(".lediv2").hide();
}
});

}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div>
<div class="lediv1" style="position: relative; width: 100%; left: 0px; top: 0px; right: 0px;background:#F00;float:left;">
<div>
<div class="text-center">Hello Hello!</div>
<div class="text-center">Hello Hello!</div>
<div class="text-center">Hello Hello!</div>
<button class="closebtnT" style="cursor:pointer;" onclick="openNav()"> go </button>
</div>
</div>
<div class="lediv2" style="display:none;position: relative; width: 100%; left: 0px; top: 0px; right: 0px;background:#FF0;float:left;">
<div>
<div class="text-center">I don't know why you say goodbye, I say hello!</div>
<div class="text-center">I don't know why you say goodbye, I say hello!</div>
<div class="text-center">I don't know why you say goodbye, I say hello!</div>
<div class="text-center">I don't know why you say goodbye, I say hello!</div>
<div class="text-center">I don't know why you say goodbye, I say hello!</div>
<div class="text-center">I don't know why you say goodbye, I say hello!</div>
<div class="text-center">I don't know why you say goodbye, I say hello!</div>
<button style="cursor:pointer;" onclick="closeNav()"> back </button>
</div>
</div>
</div>

问题是我希望 div 的位置在动画期间看起来像这样:

enter image description here

我在 CSS 中添加了 float:left 属性,但它不起作用。

我该如何解决?

我需要你的帮助。

最佳答案

function openNav() {
$("#slideWrapper").animate({left: '-100%'}, 500);
}

function closeNav() {
$("#slideWrapper").animate({left: '0%'}, 500);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div style="width:100%;overflow:hidden;">
<div id="slideWrapper" style="width:200%;position:relative;white-space:nowrap">
<div class="lediv1" style="width:50%;background:#F00;display:inline-block;">
<div>
<div class="text-center">Hello Hello!</div>
<button class="closebtnT" style="cursor:pointer;" onclick="openNav()"> go </button>
</div>
</div>
<div class="lediv2" style="width:50%;background:#FF0;;display:inline-block;">
<div>
<div class="text-center">I don't know why you say goodbye, I say hello!</div>
<button style="cursor:pointer;" onclick="closeNav()"> back </button>
</div>
</div>
</div>
</div>

关于javascript - 两个div之间的水平滑动效果与JQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53229377/

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