Javascript 在php laravel web应用程序中突出显示导航栏上的当前页面

Javascript 在php laravel web应用程序中突出显示导航栏上的当前页面,javascript,php,laravel,frontend,navigationbar,Javascript,Php,Laravel,Frontend,Navigationbar,伙计们帮帮我。。。 我试图在单击导航栏菜单选项时突出显示当前页面。 我尝试了javascript代码、php代码和laravel帮助,但仍然无法理解。请帮帮我 <script> window.addEventListener('scroll', event => { let nav = document.querySelector('.nav-container'); (window.scrollY >= 510) ? nav.classList.a

伙计们帮帮我。。。 我试图在单击导航栏菜单选项时突出显示当前页面。 我尝试了javascript代码、php代码和laravel帮助,但仍然无法理解。请帮帮我

<script>
window.addEventListener('scroll', event => { 
    let nav = document.querySelector('.nav-container'); 

    (window.scrollY >= 510) ? nav.classList.add('scroll') : nav.classList.remove('scroll');
});

     $(document).ready(function () {
        $("#tab-content li a").each(function(){
            //set all menu items to 'black
            $(this).css("color","white");

            var linkPath=$(this).attr("href");
            var relativePath=window.location.pathname.replace('http://'+window.location.hostname,'');

            //set the <a> with the same path as the current address to blue
            if(linkPath==relativePath)
                $(this).css("color","gray");
        });
});
    </script>



<main id="main"> 

   <!-- Header -->  
   <!-- Navigation -->
   <header>

    <div class="nav-container">
        <nav class="nav-checkbox">
        <a href="#" class="nav-logo">sample company</a>
            <input type="checkbox" id="tab-nav" class="tab-nav">
            <label for="tab-nav" class="tab-nav-label">Menu</label>
            <ul class="tab-content" id="tab">
                <li ><a class="active" href="{{ url('/') }}">Home</a></li>
                <li><a href="{{ ('/testimonials') }}">Testimonials</a></li>
                <li><a href="{{ url('/services') }}">Services</a></li>
                <li><a href="{{ url('/team') }}">Team</a></li>
                <li><a href="{{ url('/blog') }}">Blog</a></li>
                <li><a href="{{ url('/about') }}">About Us</a></li>
                <li><a href="{{ url('/contact') }}">Contact Us</a></li>
            </ul>
        </nav>
     </div>
  </header>  
</main>

addEventListener('scroll',event=>{
让nav=document.querySelector(“.nav容器”);
(window.scrollY>=510)?nav.classList.add('scroll'):nav.classList.remove('scroll');
});
$(文档).ready(函数(){
$(“#选项卡内容li a”)。每个(函数(){
//将所有菜单项设置为“黑色”
$(this.css(“颜色”、“白色”);
var linkPath=$(this.attr(“href”);
var relativePath=window.location.pathname.replace('http://'+window.location.hostname');
//设定
菜单

替换下面的代码并将CSS添加到“活动”类中。JS不是必需的

<li><a class="{{Request::is('/') ? 'active' : ''}}" href="{{ url('/') }}">Home</a></li>
                <li><a class="{{(Request::is('testimonials') || Request::is('testimonials/*')) ? 'active' : ''}}" href="{{ ('/testimonials') }}">Testimonials</a></li>
                <li><a class="{{(Request::is('services') || Request::is('services/*')) ? 'active' : ''}}" href="{{ url('/services') }}">Services</a></li>
                <li><a class="{{(Request::is('team') || Request::is('team/*')) ? 'active' : ''}}" href="{{ url('/team') }}">Team</a></li>
                <li><a class="{{(Request::is('blog') || Request::is('blog/*')) ? 'active' : ''}}" href="{{ url('/blog') }}">Blog</a></li>
                <li><a class="{{(Request::is('about') || Request::is('about/*')) ? 'active' : ''}}" href="{{ url('/about') }}">About Us</a></li>
                <li><a class="{{(Request::is('contact') || Request::is('contact/*')) ? 'active' : ''}}" href="{{ url('/contact') }}">Contact Us</a></li>