我在使用jQuery fadeIn()函数时遇到了一点小问题。基本上,我所拥有的是屏幕的一部分,作为主显示。我想淡入淡出这个区域的div。目前,我所拥有的可以淡出从那里开始的div,但是当我尝试淡入另一个div时,什么也没有发生。这是我到目前为止拥有的代码。
$('#aboutbtn').click(function(e){
$('#slideshowContainer').fadeOut('fast', function(){
$('#slideshowContainer').replace('<div id="about"></div>').fadeIn('slow');
});正如我所说的,这将淡出slideshowContainer目录,但是about目录并没有出现在它所在的位置。
更新--
这太尴尬了,哈哈。我正在尝试引用我的超文本标记语言中已经有的div,所以我猜replaceWith('')真的没有意义。
如果我想用我已经在HTML文档中定义的div来替换它,这不是应该起作用吗?
$('#aboutbtn').click(function(e){
$('#slideshowContainer').fadeOut('fast', function(){
$('#slideshowContainer').replace('#about').fadeIn('slow');
});要替换淡出的div的div的id。然而,当我这样做时,它只显示#about。
发布于 2013-05-10 10:59:37
jQuery对象没有replace方法,请使用replaceWith
$('#slideshowContainer').fadeOut('fast', function() {
$(this).replaceWith(function() {
return $('<div id="about">about</div>').hide().fadeIn();
});
});http://jsfiddle.net/ypgwL/
更新:
$('#slideshowContainer').fadeOut('fast', function () {
var $d = $('#about');
$(this).replaceWith($d);
$d.fadeIn();
});http://jsfiddle.net/ujWQW/
发布于 2013-05-10 11:02:17
尝试将文本放入您的div中
here's my jsfiddle
$(document).ready(function () {
$('#aboutbtn').click(function (e) {
$('#slideshowContainer').fadeOut('fast', function () {
$('#slideshowContainer').replaceWith('<div id="about">You miss this thing! </div>').fadeIn('slow');
});
});
});发布于 2013-05-10 11:03:43
下面是我认为你正在尝试做的一个完整的例子:
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#aboutbtn').click(function(e){
$('#slideshowContainer').fadeOut('fast', function(){
ele = $('<div id="about" style="display:none"></div>').fadeIn('slow');
$('#slideshowContainer').replaceWith(ele)
});
});
});
</script>
<div id="slideshowContainer"></div>
<input type="button" name="button" value="Button" id="aboutbtn">https://stackoverflow.com/questions/16474352
复制相似问题