javascript - 使用切换时使第二个 div 位于第一个 div 旁边

标签 javascript jquery toggle

切换时,第二个 div 首先出现在底部,然后出现在顶部。有没有办法让第二个div在切换时位于第一个div的左侧?

提前致谢。

http://jsfiddle.net/KFmLv/1862/

html

从右到左、从左到右滑动切换。

<hr/>
<p>
    <select class="mySelect">
        <option value="right">Right</option>
        <option value="left">Left</option>
        <option value="up">Up</option>
        <option value="down">Down</option>
    </select>
    <select class="mySelect2">
        <option value="left">Left</option>
        <option value="right">Right</option>
        <option value="up">Up</option>
        <option value="down">Down</option>
    </select>
    <button id="button" class="myButton">Toggle</button>
</p>
<div id="myDiv">
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
    <p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
</div>
<div id="myDiv2">
    <p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
</div>

JavaScript

$(".myButton").click(function () {

// Set the effect type
var effect = 'slide';

// Set the options for the effect type chosen
var options = {
    direction: $('.mySelect').val()
};
var options2 = {
    direction: $('.mySelect2').val()
};
// Set the duration (default: 400 milliseconds)
var duration = 500;

$('#myDiv').toggle(effect, options, duration);
$('#myDiv2').toggle(effect, options2, duration);

});

最佳答案

#myDiv#myDiv2 包裹在具有相对位置的元素中,并将 absolute 位置赋予 #myDiv#myDiv2

CSS:

#myDiv,#myDiv2{
    position:absolute;
    top:0;
}
.relative{
    position:relative;
}

HTML:

<div class="relative">
    <div id="myDiv">...</div>
    <div id="myDiv2">...</div>
</div>

See updated fiddle here.

关于javascript - 使用切换时使第二个 div 位于第一个 div 旁边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27242133/

相关文章:

javascript - 在 Chart.js 中绘制线上的点

javascript - 如何在 HTML 中编写算法/伪代码?

圆圈部分的jquery悬停菜单-如何?

Jquery 切换停止工作

javascript - 单击 Jquery 切换按钮的文本

javascript - Firefox 上错误的 mouseenter 事件

c# - 如何使 Accordion 标题在页面加载时全部折叠?

javascript - 让 jQuery mousemove 停止

javascript - 如何避免 Google Search Console 出现 "FID issue: longer than 300ms"?

jquery - 使用 jQuery 关闭使用数据切换属性打开的 div?