I'm hiding a div with .hide and showing with .toggle of jquery, the function is good for me the problem is that if I show it in a lower part of the docomunto, like the footer for example and click the button to show the div appears, however it takes me to the beginning of the document, how can I avoid that? I leave the example with a paragraph with a black background so when you click on the button it is obvious that the document returns.
$(document).ready(function() {
$('.lista-cotizacion').hide();
$('#btn_lista').click(function(e){
$('.lista-cotizacion').toggle('fast');
e.stopPropagation();
});
$('html').click(function(){
$('.lista-cotizacion').hide('fast');
});
});
.bar_nav {
background-color: #ad4f3f;
width: 100%;
height: 60px;
-webkit-box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.12), 0 1px 5px 0 rgba(0, 0, 0, 0.2);
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.12), 0 1px 5px 0 rgba(0, 0, 0, 0.2);
position: fixed;
}
.container-dash {
margin-top: 250px;
}
.lista-cotizacion {
background-color: white;
margin-top: 40px;
padding: 15px;
z-index: 9999;
position: fixed;
right: 0;
-webkit-transform-origin: 0 0;
transform-origin: 0 0;
-webkit-box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 10px 5px -3px rgba(0, 0, 0, 0.12), 0 4px 15px 0 rgba(0, 0, 0, 0.2);
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 10px 5px -3px rgba(0, 0, 0, 0.12), 0 4px 15px 0 rgba(0, 0, 0, 0.2);
max-width: 350px;
max-height: 80vh;
}
<!DOCTYPE html>
<html>
<head>
<!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta charset="UTF-8">
</head>
<body>
<div class="row">
<div class="col s12 bar_nav">
<a href="#" id="btn_lista" class=" btn-floating btn-large waves-effect waves-circle waves-ligh right color-dicipa"><i class="material-icons">content_paste</i></a>
</div>
</div>
<div class='lista-cotizacion'>
<div class="row">Lista de Productos :</div>
<ul>
<li>¡Lista vacia!</li>
</ul>
</div>
<div class="container container-dash">
<p style="background-color:black; color:white"> The standard Lorem Ipsum passage, used since the 1500s
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC
</p>
"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
</body>
</html>