JQuery - Cambiar nombre botón Toggle

 
Vista:
sin imagen de perfil

Cambiar nombre botón Toggle

Publicado por Cristina (2 intervenciones) el 12/05/2015 18:31:41
Buenas tardes.

Estoy haciendo una página y en el inicio hay una parte que estoy utilizando toggle cuando das a un botón aparece debajo unos precios.
El caso es que en el botón pone "ver precios" y al hacer clic aparece debajo los precios. Me gustaría que cuando pulsas cambie el texto y ponga "cerrar precios" para que la gente sepa que tienes que volverle a dar al botón para cerrar los precios...o alguna solución que al hacer clic en cualquier otro sitio de la web se cierre la ventana. No sé si me he explicado bien.

Mi código es este:

1
2
3
4
5
6
7
8
9
<script>
     jQuery(document).ready(function () {
jQuery('.click').on('click', function(e){
 
    jQuery(".precios").toggle();
    jQuery(this).toggleClass('class1', 1000, "easeOutSine")
});
         });
</script>

Muchas gracias de antemano ;)
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 302
Oro
Ha mantenido su posición en JQuery (en relación al último mes)
Gráfica de JQuery

Cambiar nombre botón Toggle

Publicado por xve (673 intervenciones) el 13/05/2015 07:23:20
Hola Cristina, aqui te adjunto un ejemplo de como lo haria... lo veo un poco raro, creo que tendria que haber una mejor manera de hacerlo, pero no se me ocurre como...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
	<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js" type="text/javascript"></script>
 
	<script>
	$(document).ready(function() {
		$("#mostrar").click(function(){
			$("#precios").toggle(function(){
				if($("#precios").css("display")=="block")
					$("#mostrar").html("esconder precios");
				else
					$("#mostrar").html("ver precios");
			});
		});
	});
	</script>
 
	<style>
	#precios {display:none;}
	</style>
</head>
 
<body>

Coméntanos si te sirve, ok?

<div id="mostrar">ver precios</div>
<div id="precios">
precios...
</div>

</body>
</html>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil

Cambiar nombre botón Toggle

Publicado por Cristina (2 intervenciones) el 13/05/2015 10:37:03
Muchas gracias!

He pegado tu código en un html y sí funciona.

El caso es que en mi php no funciona...o no lo coloco bien o no sé cómo hacerlo...

Te paso todo el código por si le puedes echar un vistazo y ayudarme ;)

Muchísimas gracias!!


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
<script>
     jQuery(document).ready(function () {
jQuery('.click').on('click', function(e){
 
    jQuery(".precios").toggle();
    jQuery(this).toggleClass('class1', 1000, "easeOutSine")
});
         });
</script>
<div class="cabecera">
<p><strong>GRUPO SETOR:</strong> CONOCE NUESTRA RED DE ESTACIONES
<? if( current_user_can('editor')||current_user_can('administrator')){  ?>
<a class="editar" href="<?php echo get_admin_url(); ?>/post.php?post=213&action=edit ">editar</a>
<?php }?>
    <span class="editar click">ver precios</span>
</p>
</div>
<div id="gasolineras">
<div class="dentro">
 
<?php  // WP_Query arguments
$args = array (
'post_type' =>'gasolinera',
	'orderby' => 'menu_order',
	'order' => 'ASC',
	'posts_per_page'=> -1
);
$lasto=1;
// The Query
$query = new WP_Query( $args );
 
// The Loop
if ( $query->have_posts() ) {
	while ( $query->have_posts() ) {
		$query->the_post();?>
		<?php if ($lasto==4){ $ultimo='last';$lasto=1; 	}else{ $ultimo=''; $lasto++;} ?>
		<div class="gasolinera <? //echo $ultimo;?>">
			<div id="foto_home">
				<? $fotos= get_field('galeria_de_fotos_imagen'); $i = 0;
					foreach($fotos  as $foto){
					   //print_r($foto);
					    $i++;
					   if ($i == 1){$last="first";?>
                <a href="<?php the_permalink()?>"><img class="foto-home <?php echo $last; ?>" width="300" src="<?php echo $foto['original']?>"/></a>
					  	<?php }else{ $last=""; } ?>
					<?php }	?>
				<a href="<?php the_permalink();?>" class="mas">+</a>
				<div class="precios class1">
			<?php   $laID = get_the_ID();
				$elementos = get_group('gasolinera',213);
		//print_r($elementos);
					foreach($elementos as $elemento){
						if ($elemento['gasolinera_seleccione_gasolinera'][1] == $laID){
							echo '<ul>';
							foreach($elemento as $key => $precio){
 
								if ($key != 'gasolinera_seleccione_gasolinera') {?>
								<li>
									<span class="tipo" style="color: #808080; "><?php
									$key = str_replace('gasolinera_','',$key);
									$key = str_replace('_',' ',$key);
									$key = ucwords($key);
									$key = str_replace('Sp','SP',$key);
									$key = str_replace('E 10','e+ 10',$key);
									$key = str_replace(' E',' e',$key);
									echo $key;?>: </span> <span class="precio"><?php
									$precioeuro= str_replace(' €','',$precio[1]);
									echo $precioeuro;?></span>
									</span>
								</li>
 
 
								<?php }
 
								//print_r($precio);
							}
							echo '</ul>';
						}
					}
				?>
			</div><!-- fin precios -->
			</div>
			<h3><span class="tit"><?php echo get('primera_columna_titulo'); ?></span></h3>
 
		</div>
<?php	}
} else {
	// no posts found
}
 
// Restore original Post Data
wp_reset_postdata();
?>
</div>
</div>
<style>
 
    .class1{
    display: none;
           -webkit-transition: all 500ms ease-out 1s;
    -moz-transition: all 500ms ease-out 1s;
    -o-transition: all 500ms ease-out 1s;
    transition: all 500ms ease-out 1s;
    }
    .editar{
    display:inline-block;}
    .baneres img{
    max-width:100%;
        height:auto;
    }
 
.foto-home{
	width: 100%;
	height: auto;
	margin: 0;
    display:block;
 
 
}
.horario{
	height:30px;
	padding: 5px;
}
#gasolineras p{
	margin: 0px;
	line-height: 12px;
	font-size: 12px;
}
#gasolineras{
	width: 100%;
	background-color: #E7E7E7;
	display: inline-block;
	padding:  0px;
}
#gasolineras .dentro{
padding: 20px 0 10px 20px;
margin: 0px;
}
.cabecera{
display: inline-block;
width: 100%;
	background: #3c93d9;
	margin: 0px;
	color: white;
	padding: 0px;
 
}
.cabecera p{
	padding: 5px 20px;
	font-size: 16px;
	margin: 0px;
}
.gasolinera{
/*height: 250px;*/
width:22%;
float: left;
margin-right: 3%;
  margin-bottom: 20px;
}
 
 
#foto_home
{
    position:relative;
}
 
.direccion{
	height: 20px;
	font-size: 11px;
}
.direccion, .masdetalles {
display: inline-block;
	padding: 5px;
 
}
 
.gasolinera h3 {
	font-size: 12px;
color: #3c93d9;
background: none repeat scroll 0 0 #fff;
	width: 100%;
	margin: 0px;
	padding: 0px;
 
}
 
#gasolineras h3 .tit{
	padding: 5px;
	font-weight: bold;
}
    #foto_home .precios {
background-color: white;
 
 
color: #3c93d9;
 
  top:0;
  left:0;
  position: absolute;
	width: 100%;
	margin: 0px;
	padding: 0px;
        height:100%;
 
}
    .mas{
    background-color: white;
color: #3c93d9;
  top:0;
  right:0;
  position: absolute;
	width: 20px;
        height:20px;
	margin: 0px;
	padding: 0px;
        text-align:center;
	color: #3c93d9;
        font-weight:bold;
 
 
    }
.tipo{
	width: 67%;
	display: inline-block;
	text-align: left;
}
.precio{
	width: 30%;
	display: inline-block;
	text-align: right;
	color: #3c93d9
}
 
.precios ul{
	list-style: none;
	margin: 0px;
	padding: 5px;
}
.precios ul li{
display: inline-block;
width: 100%;
margin: 0px;
line-height: 12px;
font-size: 12px;
}
.editar, a.editar {
	margin-left: 20px;
	font-size: 11px;
	color: white;
	background-color: #263A8A;
	padding: 3px 10px;
	-webkit-border-radius: 4px;
	-moz-border-radius: 4px;
	border-radius: 4px;
    height: 100%;
    cursor:pointer;
}
@media only screen and (max-width: 959px) and (min-width: 768px){
.gasolinera{
/*height: 250px;*/
width:30%;
float: left;
margin-right: 3%;
}
    .four_fifth {
    width:79.2%;
    }
}
@media only screen and (max-width: 767px) and (min-width: 480px){
.gasolinera{
/*height: 250px;*/
width:47%;
float: left;
margin-right: 3%;
}
#post-15 .baneres p{
width: 200px;
text-align: center;
margin: auto;
display: block;
 
}
}
@media only screen and (max-width: 480px){
.gasolinera{
/*height: 250px;*/
width:93%;
float: left;
margin-right: 6%;
text-align: center;
}
 
#post-15 .baneres p{
width: 200px;
text-align: center;
margin: auto;
display: block;
 
}
}
@media only screen and (min-width: 939px){
#rev_slider_1_1, #rev_slider_1_1_wrapper {
  width: 940px;
  height: 250px;
}
 .four_fifth {
    width:79.2%;
    }
}
 
@media only screen and (max-width: 939px) and (min-width: 780px){
#rev_slider_1_1, #rev_slider_1_1_wrapper {
  width: 750px;
  height: 200px;
}}
</style>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar