是否有可能让div淡出,然后在点击链接或按钮时使用不同内容的不同div淡入同一个地方?
它显然使用.fadeIn()和.fadeOut()函数,但我不确定所有代码的外观,特别是定位,以及在同一页面上执行两次的能力.
dSq*_*red 13
如果你想淡出一个</div>然后淡入另一个:
<div id="div1"></div>
<div id="div2" style="display: none"></div>
<div><a href="#" id="triggerButton">Swap Divs</a></div>
$('#triggerButton').click(function(e){
e.preventDefault();
$('#div1').fadeOut('fast', function(){
$('#div2').fadeIn('fast');
});
});
Run Code Online (Sandbox Code Playgroud)
如果你想</div>用另一个替换在同一个地方淡出的那个:
<div id="div1"></div>
<div><a href="#" id="triggerButton">Swap Divs</a></div>
$('#triggerButton').click(function(e){
$('#div1').fadeOut('fast', function(){
$('#div1').replace('<div id="div2"></div>').fadeIn('fast');
});
});
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助.
这里有两个框可以互相淡入淡出:http://jsfiddle.net/jfriend00/3XwZv/.
两个框定位在使用彼此的顶部position: absolute在一个position: relative容器中.
一个淡出,另一个淡入,当一个完成时,它们反转过程.jQuery代码如下所示:
var fadeinBox = $("#box2");
var fadeoutBox = $("#box1");
function fade() {
fadeinBox.stop(true, true).fadeIn(2000);
fadeoutBox.stop(true, true).fadeOut(2000, function() {
// swap in/out
var temp = fadeinBox;
fadeinBox = fadeoutBox;
fadeoutBox = temp;
// start over again
setTimeout(fade, 1000);
});
}
// start the process
fade();
Run Code Online (Sandbox Code Playgroud)
HTML看起来像这样:
<div id="wrapper">
<div id="box1" class="box"></div>
<div id="box2" class="box"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS看起来像这样:
.box {
position: absolute;
height: 100px;
width: 100px;
}
#wrapper {position: relative;}
#box1 {background-color: #F00;}
#box2 {background-color: #00F; display: none;}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24511 次 |
| 最近记录: |