Fórum Mostrar botão quando passar o mouse #487233
29/07/2014
0
Franzé Peixoto
Curtir tópico
+ 0Posts
29/07/2014
Joel Rodrigues
Poderia postar o código da sua tabela, só para eu entender como está posicionado este botão?
Gostei + 0
29/07/2014
Franzé Peixoto
<html>
<head>
<title>Tabela com Bootstrap</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Marca</th>
<th>Descrição</th>
<th>Ano</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Ford</td>
<td>Ka</td>
<td>2009</td>
<td><button class="btn btn-default">detalhes</button></td>
</tr>
<tr>
<td>Chevrolet</td>
<td>Celta</td>
<td>2011</td>
<td><button class="btn btn-default">detalhes</button></td>
</tr>
<tr>
<td>Wolksvagen</td>
<td>Gol</td>
<td>2007</td>
<td><button class="btn btn-default">detalhes</button></td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Gostei + 0
29/07/2014
Ronaldo Lanhellas
http://api.jquery.com/show/
http://api.jquery.com/hide/
Gostei + 0
29/07/2014
Joel Rodrigues
Gostei + 0
29/07/2014
Franzé Peixoto
http://api.jquery.com/show/
http://api.jquery.com/hide/
Ronaldo e Joel, vou olhar os links e pesquisar sobre eles.
Gostei + 0
29/07/2014
Franzé Peixoto
<script>
$(function(){
$("#tabela tr").hover(
function(){
//aqui mostra
},
function(){
//aqui esconde
}
);
});
</script>
Gostei + 0
29/07/2014
Joel Rodrigues
Agora a dificuldade é selecionar o botão para poder aplicar o hide e show, né? Pesquise sobre o método children para selecionar o botão como sendo filho da coluna, que é filha da linha.
Gostei + 0
30/07/2014
Ronaldo Lanhellas
<script>
$(function(){
$("#tabela tr").hover(
function(){
//aqui mostra
},
function(){
//aqui esconde
}
);
});
</script>
O caminho é esse, tente fazer o seguinte agora:
<script>
$(function(){
$("#tabela tr").hover(
function(){
if ($(".meubotao").is(":visible")) {
$(".meubotao").hide();
}else{
$(".meubotao").show();
}
}
);
});
</script>
Gostei + 0
30/07/2014
Franzé Peixoto
Gostei + 0
31/07/2014
Franzé Peixoto
<td><button class="btn btn-default meubotao">detalhes</button></td>
Mas quando passo o mouse em cima da tabela, todos os botões somem de uma vez.
Gostei + 0
31/07/2014
Joel Rodrigues
Tente o seguinte:
<script>
$(function(){
$("#tabela tr").hover(
function(){
$(this).children(4).children(0).show();
},
function(){
$(this).children(4).children(0).hide();
}
);
});
</script>Gostei + 0
31/07/2014
Franzé Peixoto
Gostei + 0
31/07/2014
Franzé Peixoto
Gostei + 0
31/07/2014
Joel Rodrigues
$("#tabela button").hide();antes dessa parte:
$("#tabela tr").hover(...Gostei + 0
31/07/2014
Franzé Peixoto
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)