I am working on my first Blazor page. I am not a UI designer so I primarily know C#. I don't know Javascript at all. I have downloaded an HTML template to help me with the design part. This template uses Javascript to do some nice effects on the top navigation.
Is it possible to access this script and have it loaded when the page is initialized? I have put for the scripts in index.html and the appropriate references in the html code in index.cshtml.
I have read and tried some things with JSinterop, without progress.
Is there some relatively easy sollution to this, or does it involve a lot of intricate code JSruntime etc?
Index.html:
<!-- Custom scripts for this template -->
<script src="js/grayscale.min.js"></script>
Index.cshtml:
<!-- Navigation -->
<!-- Header -->
<div id="page-top">
<nav class="navbar navbar-expand-lg navbar-light fixed-top" id="mainNav">
<div class="container">
<a class="navbar-brand js-scroll-trigger" href="#pagetop">MyPage</a>
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
Menu
<i class="fas fa-bars"></i>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#about">Om Travblaze</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#projects">Verktøy</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#signup">Kontakt</a>
</li>
</ul>
</div>
</div>
</nav>
grayscale.js:
(function ($) {
"use strict"; // Start of use strict
// Smooth scrolling using jQuery easing
$('a.js-scroll-trigger[href*="#"]:not([href="#"])').click(function() {
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
if (target.length) {
$('html, body').animate({
scrollTop: (target.offset().top - 70)
}, 1000, "easeInOutExpo");
return false;
}
}
});
// Closes responsive menu when a scroll trigger link is clicked
$('.js-scroll-trigger').click(function() {
$('.navbar-collapse').collapse('hide');
});
// Activate scrollspy to add active class to navbar items on scroll
$('body').scrollspy({
target: '#mainNav',
offset: 100
});
// Collapse Navbar
var navbarCollapse = function() {
if ($("#mainNav").offset().top > 100) {
$("#mainNav").addClass("navbar-shrink");
} else {
$("#mainNav").removeClass("navbar-shrink");
}
};
// Collapse now if page is not at top
navbarCollapse();
// Collapse the navbar when page is scrolled
$(window).scroll(navbarCollapse);
})(jQuery); // End of use strict