JQuery - Bloquear scroll

 
Vista:
Imágen de perfil de marti

Bloquear scroll

Publicado por marti (5 intervenciones) el 25/01/2016 21:36:06
Hola,
Estoy intentando bloquear el scroll para que cuando abra una capa, la que esta debajo no se pueda subir ni bajar.
Lo quiero hacer con ajax i passarle la variable al abrir la capa pero no me funciona.
La funcion JQUERY comienza en la linia 121

569fbf7fd54c6-xd

Pagina principal:
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
<!-- Aquesta es la pàgina principal de comprar fotos de reportatges. -->
 
<?
if (! isset ( $_SESSION )) {
	session_start ();
}
 
?>
 
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
 
<!-- CSS de Bootstrap -->
<link href="../codiFont/css/bootstrap.min.css" rel="stylesheet"
	media="screen">
 
<!-- librerías opcionales que activan el soporte de HTML5 para IE8 -->
<!--[if lt IE 9]-->
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script
	src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
 
<!-- CSS propi -->
<link href="../codiFont/css/fullaEstil.css" rel="stylesheet"
	media="screen">
 
<!-- Funcions JavaScript -->
<script src="javaScript/funcions.js"></script>
 
<!-- Foto Icona -->
<link rel="icon" type="image/png" href="../codiFont/css/logo.png" />
 
<!-- Llibreria JQuery-->
<script type="text/javascript" src="../codiFont/js/jquery-2.1.4.min.js"></script>
 
</head>
 
<body>
 
 
 
	<!-- Scrips JQuery -->
	<script>
    // Resize de la capa capaPreus.
   $(document).ready(function(){
 
     	$(window).resize(function(){
           // li passem la clase o l'id de la capa.
          $('#capaPreus').css({
               position:'fixed',
               left: ($(window).width() - $('#capaPreus').outerWidth())/2,
               top: ($(window).height() - $('#capaPreus').outerHeight())/2
          });
 
    });
 
    // Executem la funció.
    $(window).resize();
 
    });
 
	// Ajustem la llargada del fons opac negre.
	$(document).ready(function(){
 
     	$(window).resize(function(){
         // li passem la clase o l'id de la capa.
          $('.fadebox').css({
               position:'fixed',
               left: ($(window).width() - $('.fadebox').outerWidth())/2,
               top: ($(window).height() - $('.fadebox').outerHeight())/2
          });
 
    });
 
    // Executem la funció.
    $(window).resize();
 
    });
 
 
	// Resize de la capa contacte.
	$(document).ready(function(){
 
     	$(window).resize(function(){
         // li passem la clase o l'id de la capa.
          $('#capaContacte').css({
               position:'fixed',
               left: ($(window).width() - $('#capaContacte').outerWidth())/2,
               top: ($(window).height() - $('#capaContacte').outerHeight())/2
          });
 
    });
 
    // Executem la funció.
    $(window).resize();
 
    });
 
	// Resize de la capa cistella.
	$(document).ready(function(){
 
     	$(window).resize(function(){
         // li passem la clase o l'id de la capa.
          $('#capaCistella').css({
               position:'fixed',
               left: ($(window).width() - $('#capaCistella').outerWidth())/2,
               top: ($(window).height() - $('#capaCistella').outerHeight())/2,
 
          });
 
    });
 
    // Executem la funció.
    $(window).resize();
 
    });
 
	$(window).scroll(function (event) {
		if($("#variable").val() == "1"){
			$(window).scrollTop(0);
		}
		// Do something
	});
 
	</script>
 
	<div class="alert alert-success alert-dismissable">
		<button type="button" class="close" data-dismiss="alert">&times;</button>
		Clica la foto que vulguis per demanar-ne una còpia.
	</div>
 
	<div align="center" id="galeria">
 
		<br />
 
<?
 
 
?>
 
	</div>
 
	<!-- Capa de Preus -->
	<div id='capaPreus' class="overbox" style='display: none'></div>
 
	<!-- Capa de la Cistella -->
	<div id='capaCistella' class="overbox" style='display: none'></div>
 
	<!-- Capa de Contacte -->
	<div id='capaContacte' class="overbox" style='display: none'></div>
 
	<!-- Capa Lightbox -->
	<div id="fade" class="fadebox">&nbsp;</div>
 
	<!-- Librería jQuery requerida por los plugins de JavaScript -->
	<script src="http://code.jquery.com/jquery.js"></script>
 
	<!-- Todos los plugins JavaScript de Bootstrap (también puedes
         incluir archivos JavaScript individuales de los únicos
         plugins que utilices) -->
	<script src="../codiFont/js/bootstrap.min.js"></script>
 
</body>
</html>

Metodo para abrir la capa:

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
function modificarDetallFoto(a){
 
	document.getElementById('capaPreus').style.display='block';
 
	document.getElementById('fade').style.display='block';
 
	var variable = 1;
 
	var xmlhttp;
 
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
 
			document.getElementById("capaPreus").innerHTML=xmlhttp.responseText;
 
			$('#tamany').change(function(){
				var valor = $('#tamany').val();
 
				if (valor != "CD/4.00") {
 
					document.getElementById('quantitatFotos').style.display='block';
				}
 
				if (valor == "CD/4.00") {
 
					document.getElementById('quantitatFotos').style.display='none';
				}
 
				if (valor == "res") {
 
					document.getElementById('quantitatFotos').style.display='none';
				}
 
			});
 
		}
	}
	xmlhttp.open("POST","posarPreusFotos.php?variable=1&nomarxiu="+a,true);
	xmlhttp.send();
}
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

Bloquear scroll

Publicado por xve (673 intervenciones) el 26/01/2016 08:16:30
Hola Marti, una manera, es esta:

para eliminar el scroll:
1
2
3
4
$('html, body').css({
    'overflow': 'hidden',
    'height': '100%'
});

para restaurarlo:
1
2
3
4
$('html, body').css({
    'overflow': 'auto',
    'height': 'auto'
});

Espero que te sirva.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
2
Comentar

Bloquear scroll

Publicado por ray delfin (1 intervención) el 06/05/2017 01:45:16
Me funciono lo que publico xve para ocultar el scroll:
1
2
3
4
5
// Quitar Scroll
$('html, body').css({
    'overflow': 'visible',
    'height': 'auto'
});

Pero para volver a ser visible el scroll use esto:
1
2
3
4
5
// Mostrar Scroll
$('html, body').css({
    'overflow': 'visible',
    'height': 'auto'
});

Saludos
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