1
I’m using the tab of the materialize, the switch works normally, but every time I click on a tab moves the page to the top, I don’t know why, I believe it has to do with the smooth scroll effect, but I’m not sure
<!--Import materialize.css-->
<link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css" media="screen,projection">
<div style='margin-top: 500px' id='tudo' class="col s12">
<ul class="tabs">
<li class="tab col s4"><a class='active' href="#minhas">Minhas</a></li>
<li class="tab col s4"><a href="#favoritas">Favoritas</a></li>
<li class="tab col s4"><a href="#publicas">Públicas</a></li>
</ul>
<!-- LISTA DE MINHAS -->
<div class="row" id="minhas"></div>
<!-- LISTA FAVORITAS -->
<div class="row" id="favoritas"></div>
<!-- LISTA PÚBLICAS -->
<div class="row" id="publicas"></div>
</div>
<footer>
<!-- Import JQuery.js -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Smooth scrolling effect -->
<script>
$(document).scroll(function() {
$('a[href^="#"]').on('click', function(e) {
e.preventDefault();
var target = this.hash;
var $target = $(target);
$('html, body').stop().animate({
'scrollTop': $target.offset().top
}, 900, 'swing');
});
});
$(document).ready(function() {
$('.tabs').tabs();
});
</script>
<!-- Import materialize.js-->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/js/materialize.min.js"></script>
</footer>
Don’t you want the page to go to the top when switching tab? This is the unwanted effect?
– guastallaigor
@guastallaigor because this tab is in the middle of html, where different things are shown depending on the tab, it is very bad to click on favorites to see your favorites and be played to the top and have to scroll down everything again to see the content
– Costamilam
Aham quiet, just wanted to make sure you understood correctly, I’ll try something here without taking your smooth scroll effect.
– guastallaigor