我使用Bootstrap,jQuery,jQueryUI,并希望在用户回答问题并点击" Valider"时将三个面板移到左侧。
使用CSS叠加技巧(.opacity-gauche
和.opacity-droite
)
我所看到的效果是:
.panel-left
div应该消失然后被移除。.panel-main
成为.panel-left
.panel.right
成为.panel.main
.panel-right
并且'滑动'从右边开始。代码:
<div class="row">
<div class="col-sm-4 hidden-xs" style="position:relative">
<div class="panel panel-default text-center panel-left">
<div class="panel-heading"><h3 class="panel-title">Question <span class="question-numero">1</span> sur <span class="question-nombre-total">5</span></h3></div>
<div class="panel-body text-center">
<h3 class="question-donnee">5 × 3 = 15</h3>
<div class="input-group mt20 invisible">
<div class="input-group-addon">=</div>
<input type="text" class="form-control" id="question-reponse" placeholder="Réponse">
</div>
<div class="btn btn-primary btn-block mt20 invisible" id="">Valider</div>
</div>
</div>
<div style="position:absolute;width:100%;height:100%;top:0px;left:0px;z-index:1000" class="opacity-gauche"> </div>
</div>
<div class="col-xs-12 col-sm-4" style="position:relative">
<div class="panel panel-default text-center panel-main">
<div class="panel-heading"><h3 class="panel-title">Question <span class="question-numero">2</span> sur <span class="question-nombre-total">5</span></h3></div>
<div class="panel-body">
<h3 class="question-donnee">5 × 3</h3>
<div class="input-group mt20">
<div class="input-group-addon">=</div>
<input type="text" class="form-control" id="question-reponse" placeholder="Réponse">
</div>
<div class="btn btn-primary btn-block mt20" id="question-valider">Valider</div>
</div>
</div>
</div>
<div class="col-sm-4 hidden-xs" style="position:relative">
<div class="panel panel-default text-center panel-right">
<div class="panel-heading"><h3 class="panel-title">Question <span class="question-numero">3</span> sur <span class="question-nombre-total">5</span></h3></div>
<div class="panel-body text-center">
<h3 class="question-donnee">Prochaine question</h3>
<div class="input-group mt20 invisible">
<div class="input-group-addon">=</div>
<input type="text" class="form-control" id="" placeholder="Réponse">
</div>
<div class="btn btn-primary btn-block mt20 invisible" id="question-valider">Valider</div>
</div>
</div>
<div style="position:absolute;width:100%;height:100%;top:0px;left:0px;z-index:1000" class="opacity-droite"> </div>
</div>
</div>
<script>
$('#question-valider').click(function(ev){
var panelwidth = $('.panel-main').width();
//var panelright = $('.panel-right').width();
$('.panel-left').animate({'width':"0px"}, 400);
$('.panel-right').css('position','absolute').css('width', panelwidth+'px').animate({'left':"-"+($('.panel-main').parent().width()+15)+"px"}, 400);
$('.panel-main').css('position','absolute').css('width', panelwidth+'px').animate({'left':"-"+($('.panel-main').parent().width()+15)+"px"}, 400);
});
</script>
感谢您的帮助!
罗勒