I want to have my whole website as one page.
When clicking on different links in the navigation bar, the content should cross-fade from the old to the new one.
Example: I am on index.html#home and click on About. This should cross-fade between the divs #home and #about.
Using W3CSS and jQuery I managed to hide the content like this:
function hideContent() {
$(".content-active").addClass("w3-hide", "content-inactive");
$(".content-active").removeClass("w3-show", "content-active");
};
<link href="https://www.w3schools.com/w3css/4/w3.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="#home" class="w3-bar-item w3-hide-small" style="width:16.5%">Home</a>
<a href="#about" class="w3-bar-item w3-hide-small" style="width:16.5%" onclick="hideContent()">About</a>
<div id="home" class="w3-container w3-green w3-show content-active" style="height:50px"></div>
<div id="about" class="w3-container w3-red w3-hide content-inactive" style="height:50px"></div>
I am not able to show the new content though. I wanted to add an onclick function to the navigation link and then extract the href-value to again change the class names for the div that has the ID of the href-value.
But doing this on <a href="#" onclick="showContent()></a> returns undefined:
function showContent() {
var hrefValue = $(this).attr("href");
alert(hrefValue);
}
I guess this is not in the proper scope of <a> here. Am I assuming correctly?
What would be an easy way to show the content otherwise?