Reputation: 75
I tried adding smooth scrolling to my website. After copying the javascript and jquery from this website: http://www.dwuser.com/education/content/quick-guide-adding-smooth-scrolling-to-your-webpages/ I added the tags for the smooth scrolling. The smooth scrolling works for everything except one button on the nav bar. This is the code:
<nav id="nav">
<div class="navbar">
<div class="brand"><a href="#" class="smoothScroll">hbvhaf</a></div>
<ul>
<li><a href="#welcome" class="smoothScroll"><span>about</span></a></li>
<li><a href="#hotelinfo" class="smoothScroll"><span>bvdsvudva</span></a></li>
<li><a href="#dining" class="smoothScroll"><span>contact</span></a></li>
</ul>
</div><!-- navbar -->
</nav>
The one button that doesn't smooth scroll is the one that has a div class of "brand". The div is used to specifically style that button in css. Any ideas.
Upvotes: 1
Views: 226
Reputation: 14313
I know that this is a bit of a hack, but why don't you just add this to the top of the page:
<div name="top"></div>
And then change your code to:
<nav id="nav">
<div class="navbar">
<div class="brand"><a href="#top" class="smoothScroll">hbvhaf</a></div>
<ul>
<li><a href="#welcome" class="smoothScroll"><span>about</span></a></li>
<li><a href="#hotelinfo" class="smoothScroll"><span>bvdsvudva</span></a></li>
<li><a href="#dining" class="smoothScroll"><span>contact</span></a></li>
</ul>
</div><!-- navbar -->
</nav>
Edit for author, example of it working properly:
<div name="top">I am the top of the page.</div>
<a href="#contact" class="smoothScroll">Go To Contact Form</a>
<div style="height:200%"></div>
<div name="contact">contact</div>
<a href="#top" class="smoothScroll">Back to top</a>
<div style="height:200%"></div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="smoothscroll.js"></script>
Upvotes: 1