简体   繁体   English

jQuery的幻灯片效果

[英]slide effect with jquery

I'd like to create a slide effect using jQuery. 我想使用jQuery创建幻灯片效果。 I have several div's: 我有几个div:

<div id='div_1'>content currently displayed</div>
<div id='div_2' style="display:none">content to be loaded</div>
<div id='div_3' style="display:none">content to be loaded</div>

The idea is that div_2 appears while sliding and "pushing" div_1 out of sight, a little like scrolling a window (horizontal or vertical). 这个想法是div_2会在滑动div_1并将其“推”到视线之外时出现,就像滚动窗口(水平或垂直)一样。 I think I can't use actual scrolling because the divs' content is loading via ajax, so I can't position it precisely before it's loaded. 我想我不能使用实际的滚动,因为divs的内容是通过ajax加载的,所以我无法在加载之前精确定位它。

Any idea? 任何想法?

TIA TIA

greg 格雷格

You mean like this: 您的意思是这样的:

$('#div_2').slideDown('slow', function(){
  $('#div_1').slideUp('slow');
});

See the working demo here. 在这里查看工作演示。

Greg, it sounds like you are looking for something like I have done here: 格雷格,听起来您正在寻找我在这里所做的事情:

http://jsfiddle.net/2E5Qv/ http://jsfiddle.net/2E5Qv/

If so, what you want to do is to contain all of those <div> s inside a parent, and then when you want to slide them, animate the top of each div up the correct number of pixels. 如果是这样,您想要做的是将所有这些<div>包含在父级中,然后在滑动它们时,请为每个div的顶部设置正确数量的像素动画。 The solution I provided above has each <div> more or less set to a fixed height of 20px (via line-height ). 我上面提供的解决方案将每个<div>或多或少设置为20px的固定高度(通过line-height )。

The parent <div> acts as a sort of window to show only the current content. <div>充当一种窗口,仅显示当前内容。

I took what Sarfraz provided and modified it slightly based on what I think you were looking for. 我接受了Sarfraz提供的内容,并根据我认为的要求对其进行了稍微的修改。 For the sake of the demo, I also made it fire on the click event. 为了演示起见,我还使其在click事件上触发。 You can find the working example here: http://jsbin.com/emowu3/3 您可以在这里找到工作示例: http : //jsbin.com/emowu3/3

$('#div_1').click(function(){
    $('#div_1').slideUp('slow');
    $('#div_2').slideDown('slow');
});
$('#div_2').click(function(){
    $('#div_2').slideUp('slow');
    $('#div_3').slideDown('slow');
});
$('#div_3').click(function(){
    $('#div_3').slideUp('slow');
    $('#div_1').slideDown('slow');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM