jQuery隐藏一个div显示另一个 [英] jQuery hide one div show another

查看:475
本文介绍了jQuery隐藏一个div显示另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下网站: http://driz.co.uk/taschen/

我想这样做,以便当用户单击切换div时,当前显示的ipad淡出,另一个ipad淡入.反之亦然.

I'm wanting to make it so when a user clicks the toggle div the currently shown ipad is faded out and the other ipad is faded in. And vice-versa.

我该如何使用jQuery?谢谢.

How do I do this using jQuery? Thanks.

推荐答案

您可以使用 .toggle() 在功能之间交替,例如:

You can do it by using .toggle() to alternate between functions, like this:

$("#toggle").toggle(function() {
  $("#ipad-portrait").fadeOut(function() { $("#ipad-landscape").fadeIn(); });
}, function() {
  $("#ipad-landscape").fadeOut(function() { $("#ipad-portrait").fadeIn(); });
});

或者,使用 .click() (有几种方法,这是其中一种) :

Or, using .click() (there are a few ways, this is one of them):

$("#toggle").click(function() {
  var ipads = $("#ipad-portrait, #ipad-landscape"), 
      current = ipads.filter(":visible").fadeOut(function() {
                  ipads.not(current).fadeIn();
                });
});

这篇关于jQuery隐藏一个div显示另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆