我一直在寻找如何让一个JQuery滑出div。有一些文件,但我找不到适合我的问题。
我只是希望文字1 滑出左,同时文字2 从滑入正确并在屏幕上居中。
这是代码^ - ^。
enter code here
https://jsfiddle.net/sru33se6/4/
答案 0 :(得分:2)
我不知道这是否是更好的方法,但你可以尝试这样做:
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.0/css/materialize.min.css">
<link rel="stylesheet" href="../css/test.css">
</head>
<body>
<div id="content" class="content">
<!--Text 1 slides smooth out to the left.-->
<div class="text"><h1>Text 1</h1><h1>
Text 2
</h1></div>
<!--Text 2 should slide in to the right after Text 2 slided out. Currently commented out Text 2 below-->
<!--<div class="text" style="display: hidden;"><h1>Text 2</h1></div>-->
</div>
</body>
</html>
divide :: Float -> Float -> Float
divide x y = x / y
答案 1 :(得分:1)
我是使用jquery ui切换幻灯片完成的。在下面运行代码段(单击任意位置以滑动文本)
var startWithText1 = true;
var first;
var second;
$(document).click(function() {
if (startWithText1) {
first = $("#text1");
second = $("#text2");
} else {
first = $("#text2");
second = $("#text1");
}
first.toggle("slide", {
'direction': 'left'
}, 500,
function() {
second.toggle("slide", {
'direction': 'right'
}, 500)
}
);
startWithText1 = !startWithText1;
});
&#13;
body {
display: flex;
overflow-x: hidden;
overflow-y: hidden;
}
.content {
display: flex;
margin-left: auto;
margin-right: auto;
}
.text {
width: 200px;
height: 100px;
background-color: teal;
font-size: 72px;
color: white;
display: flex;
border: 4px solid black;
border-radius: 5px;
margin-left: 10px;
}
.text h1 {
margin-left: auto;
margin-right: auto;
margin-top: auto;
margin-bottom: auto;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.0/css/materialize.min.css">
<link rel="stylesheet" href="../css/test.css">
<div id="content" class="content">
<!--Text 1 slides smooth out to the left.-->
<div class="text">
<h1 id="text1">Text 1</h1>
<h1 id="text2" style="display: none;">Text 2</h1>
</div>
</div>
&#13;