突出显示滚动菜单项

时间:2017-12-20 04:28:18

标签: javascript html css

我们有一个网站。它有导航部分和一些菜单。这是一个单页面应用程序。

要求是,如果我们在家中或任何其他部分,它应突出显示相应的菜单。它应该滚动到所需的部分。

在此示例网站中,我将在平滑滚动期间突出显示菜单项。我尝试了$(' body')。scrollspy({target:'#menu'})这个但是无法帮助我



*/


(function ($) {
    'use strict';

    jQuery(document).ready(function () {

        
       /* Preloader */
		
        $(window).load(function () {
            $('.preloader').delay(800).fadeOut('slow');
        });
		
		
		
       /* Smooth Scroll */

        $('a.smoth-scroll').on("click", function (e) {
            var anchor = $(this);
            $('html, body').stop().animate({
                scrollTop: $(anchor.attr('href')).offset().top - 50
            }, 1000);
            e.preventDefault();
        });
		


       $('body').scrollspy({ target: '#menu' })

       /* Scroll Naviagation Background Change with Sticky Navigation */
		 
        $(window).on('scroll', function () {
            if ($(window).scrollTop() > 100) {
                $('.header-top-area').addClass('navigation-background');
            } else {
                $('.header-top-area').removeClass('navigation-background');
            }
        });
		
		
		
		
       /* Mobile Navigation Hide or Collapse on Click */
		
        $(document).on('click', '.navbar-collapse.in', function (e) {
            if ($(e.target).is('a') && $(e.target).attr('class') != 'dropdown-toggle') {
                $(this).collapse('hide');
            }
        });
        $('body').scrollspy({
            target: '.navbar-collapse',
            offset: 195
        
		 });
		 
		
		
		
        /* Scroll To Top */
		
        $(window).scroll(function(){
        if ($(this).scrollTop() >= 500) {
            $('.scroll-to-top').fadeIn();
         } else {
            $('.scroll-to-top').fadeOut();
         }
	   });
	
	
	    $('.scroll-to-top').click(function(){
		  $('html, body').animate({scrollTop : 0},800);
		  return false;
	    });
		

        
        /* Tooltip */
         
         $(function () {
           $('[data-toggle="tooltip"]').tooltip()
           })
		   
		 
        
        /* Ajaxchimp for Subscribe Form */
		
         $('#mc-form').ajaxChimp();

/* Global Style */

body {
    font-size: 12px;
    font-weight: 400;
    line-height: 24px;
    letter-spacing: 1px;
    height: 100%;
    font-family: 'Poppins', sans-serif;
}

html,
body {
    height: 100%
}

::selection {
    background-color: #f7639a;
    color: #ffffff;
}

::-moz-selection {
    background-color: #f7639a;
    color: #ffffff;
}

h1,
h2,
h3,
h4,
h5,
h6 {
	font-family: 'Poppins', sans-serif;
}

a {
    text-decoration: none;
}

img {
    width: 100%;
}

a {
    color: #4c9cef;
}

a:hover,
a:active{
    background: pink;
}
a:focus {
    /*color: #f7639a;
    text-decoration: none;
	outline: none;*/
}

p {
    line-height: 28px;
}

b {
	font-weight: 600;
}

ul,
li {
    margin: 0;
    padding: 0;
}

fieldset {
    border: 0 none;
    margin: 0 auto;
    padding: 0;
}

.no-padding {
    padding: 0
}

.pink-color {
	color: #f7639a !important;
}

.pink-color-bg {
	background-color: #f7639a !important;
}

.section-space-padding {
    padding: 100px 0px;
}

.section-title {
    text-align: center;
}

.section-title h2 {
    margin-top: 0;
    font-weight: 600;
    font-size: 30px;
}

.section-title p {
    font-weight: 400;
	line-height: 25px;
	margin-bottom: 40px;
}

.bg-cover {
	background-repeat: no-repeat;
}

.pattern-bg {
	background: url(../images/bg/pattern-bg.png);
	background-repeat: repeat;
}

.grabbing {
	cursor: url(../images/owl-carousel/grabbing.png) 8 8, move;
}

.divider > i {
	color: #f7639a;
	font-size: 21px;
}

.divider {
	position: relative;
	width: 126px;
	margin: 0 auto;
	overflow: hidden;
	text-align: center;
}

.divider:after,
.divider:before {
	content: ' ';
	width: 43px;
	position: absolute;
	border-bottom: dotted 2px #ffffff;
	top: 50%;
	margin-top: -4px;
}

.divider:before {
	left: 0;
}

.divider:after {
	right: 0;
}

.divider.dark:after,
.divider.dark:before {
	border-color: #b2b2b2;
}

.button {
	border: none;
	border-radius: 5px;
	font-family: inherit;
	font-size: 17px;
	color: inherit;
	background: none;
	cursor: pointer;
	padding: 20px 60px;
	display: inline-block;
	text-transform: uppercase;
	letter-spacing: 1px;
	font-weight: 700;
	outline: none;
	position: relative;
	-webkit-transition: all 0.3s;
	-moz-transition: all 0.3s;
	transition: all 0.3s;
}

.button:after {
	content: '';
	position: absolute;
	z-index: -1;
	-webkit-transition: all 0.3s;
	-moz-transition: all 0.3s;
	transition: all 0.3s;
}

.button-style {
	border: 3px solid #fff;
	color: #fff;
}

.button-style:hover,
.button-style:active,
.button-style:focus {
	color: #ffffff;
	background: #4c9cef;
}

.button-style-color-2:hover,
.button-style-color-2:active,
.button-style-color-2:focus {
	color: #ffffff;
	background: #f7639a !important;
}

.button-style-dark {
	border: 3px solid #000000;
	color: #000000;
}



/* Preloader */

.preloader {
    background: #F9F9F9;
    bottom: 0;
    left: 0;
    position: fixed;
    right: 0;
    top: 0;
    z-index: 99999;
}

.preloader p {
    position: absolute;
    top: 48%;
    left: 50%;
    text-align: center;
    font-size: 20px;
    color: #333333;
}

.preloader:before, .preloader:after {
    content: "";
    width: 20px;
    height: 20px;
    position: absolute;
    top: 40%;
    left: 40%;
    background-color: #4c9cef;
    animation: squaremove 1s ease-in-out infinite;
    -webkit-animation: squaremove 1s ease-in-out infinite;
}

.preloader:after {
    bottom: 0px;
    background-color: #f7639a;
    animation-delay: 0.3s;
}

@keyframes squaremove {
  0%, 100%{
    -webkit-transform: translate(0,0) rotate(0);
    -ms-transform: translate(0,0) rotate(0);
    -o-transform: translate(0,0) rotate(0);
    transform: translate(0,0) rotate(0);
  }

  25%{
    -webkit-transform: translate(40px,40px) rotate(45deg);
    -ms-transform: translate(40px,40px) rotate(45deg);
    -o-transform: translate(40px,40px) rotate(45deg);
    transform: translate(40px,40px) rotate(45deg);
  }

  50%{
    -webkit-transform: translate(0px,80px) rotate(0deg);
    -ms-transform: translate(0px,80px) rotate(0deg);
    -o-transform: translate(0px,80px) rotate(0deg);
    transform: translate(0px,80px) rotate(0deg);
  }

  75%{
    -webkit-transform: translate(-40px,40px) rotate(45deg);
    -ms-transform: translate(-40px,40px) rotate(45deg);
    -o-transform: translate(-40px,40px) rotate(45deg);
    transform: translate(-40px,40px) rotate(45deg);
  }
}



/* Home Section and Navigation Menu */

.home-section {
    background: #f1f1f1;
    padding-top: 60px;
}

.table {
	margin-bottom: 0px;
}

.table a {
	color: #ffffff;
}

.table > tbody > tr > td {
	padding: 15px;
	border: 3px solid #e4e4e4;
}

.table tr > td {
	padding: 11px 13px;
}

tr:nth-child(1) > td {
	border-top:0px;
}

tr > td:nth-child(1){
	background-color: #ffffff;
	font-weight: 500;
	font-size: 13px;
	color: #888888;
	width: 140px;
}

tr > td:nth-child(2) {
	font-weight: 500;
	color: #ffffff;
	background: #4c9cef;
}

.header-top-area {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    z-index: 9999;
    -webkit-transition: all 0.4s ease-out;
    transition: all 0.4s ease-out;
}

.logo {
    padding-top: 28px;
    -webkit-transition: all 0.3s ease-out;
    transition: all 0.3s ease-out;
}

.logo a {
    display: block;
    color: #333333;
    letter-spacing: 6px;
    font-weight: 600;
    font-size: 14px;
	border-bottom: 4px solid #f7639a;
    width: 92px;
}

.navigation-menu .navbar-nav li a {
    color: #333333;
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: 1px;
    padding: 30px 15px;
    -webkit-transition: .3s;
    transition: .3s;
    font-weight: 600;
}

.navigation-menu .navbar-nav li a:hover {
    background: none;
    color: #f7639a;
    -webkit-transition: all 0.3s ease-out;
    transition: all 0.3s ease-out;
}

.nav li a:focus,
.nav li a:hover {
    background: none;
    color: #4c9cef;
    -webkit-transition: all 0.3s ease-out;
    transition: all 0.3s ease-out;
}

.navbar {
    margin: 0;
}

.navigation-background {
    -webkit-transition: all 0.3s ease-out;
    transition: all 0.3s ease-out;
    background: #4c9cef;
}

.navigation-background .logo {
    padding-top: 18px;
    -webkit-transition: all 0.3s ease-out;
    transition: all 0.3s ease-out;
}

.navigation-background .logo a {
	color: #ffffff;
}

.navigation-background .navigation-menu .navbar-nav li a {
    color: #fff;
    padding: 20px 15px;
    -webkit-transition: .3s;
    transition: .3s;
}

.navigation-background .navigation-menu .navbar-nav li a:hover {
    color: #fff;
}







/* Scroll To Top */

.scroll-to-top {
    background-color: #4c9cef;
    display: none;
    width: 60px;
    height: 60px;
    font-size: 25px;
	border-radius: 100%;
    line-height: 67px;
    text-align: center;
    color: #fff;
    position: fixed;
    right: 20px;
    bottom: 30px;
    z-index: 999;
    box-shadow: 0px 1px 2px 0px rgba(90, 91, 95, 0.15);
    transition: all 0.3s ease-in-out;
}

.scroll-to-top:hover,
.scroll-to-top:focus {
    background-color: #f7639a;
    color: #ffffff;
    box-shadow: 0px 16px 22px 0px rgba(90, 91, 95, 0.3);
}



/* Responsive */

@media only screen and (max-width: 1199px) {
	.experience-circle i {
		font-size: 30px;
	}
	
	.experience-content{
		margin-left: 75px;
	}
	
	.experience-content:after, 
	.experience-content:before {
		top: 30%;
	}
}


@media only screen and (min-width: 767px) and (max-width: 991px) {
    .navigation-menu .navbar-nav li a {
        padding: 30px 11px;
        font-size: 12px;
    }
    
	.navigation-background .navigation-menu .navbar-nav li a {
        padding: 30px 11px;
        font-size: 12px;
    }
	
	.navigation-background .logo {
		padding-top: 28px;
	}
	
	.margin-left-setting {
		margin-left: 0px !important;
	}
}


@media only screen and (max-width: 991px) {
     .call-to-action h2 {
        font-size: 20px;
	 }
}


@media only screen and (max-width: 767px) {
    .navbar-toggle .icon-bar {
        background: #f7639a;
    }
    
	.navigation-background .navbar-toggle .icon-bar {
        background: #ffffff;
    }
    
	.navbar-toggle {
        margin-right: 0px;
        margin-top: -30px;
    }
    
	.navbar {
        min-height: 0px;
    }
    
	.navigation-menu .navbar-nav li a {
        padding: 11px 15px;
		color: #ffffff;
    }
    
	.navigation-menu .navbar-nav li a:hover {
        color: #ffffff;
    }
    
	.navigation-background .navigation-menu .navbar-nav li a:hover {
        color: #ffffff;
    }
    
	.navigation-background .navigation-menu .navbar-nav li a {
        padding: 11px 15px;
    }
    
	.navbar-fixed-bottom .navbar-collapse,
    .navbar-fixed-top .navbar-collapse {
        max-height: 420px;
    }
    
	.navbar-toggle {
        margin-top: -30px;
    }
    
	.navbar-collapse {
        background: #4c9cef;
    }
    
	.navigation-background .navbar-collapse {
        background: #4c9cef;
    }
    
	.section-title h2 {
        font-size: 22px;
    }
    
	.testimonial-word {
        padding: 0;
    }
    
	.testimonial-carousel-list {
        margin-top: 0px;
    }
    
	.call-to-action h2 {
        font-size: 18px;
        line-height: 35px;
	}
    
	.contact-us-detail {
        left: 39%;
    }
    
	.owl-prev {
        left: 5px;
    }
    
	.owl-next {
        right: 5px;
    }
    
	.scroll-to-top {
        width: 45px !important;
        height: 45px !important;
        font-size: 20px !important;
        line-height: 52px !important;
        right: 8px !important;
        bottom: 15px !important;
    }
}


@media only screen and (max-width: 555px) {
	.social-icon li a {
         width: 40px;
         height: 40px;
         line-height: 44px;
         font-size: 16px;
      }
	  
     .section-title h2 {
         font-size: 16px;
		 font-weight: 500;
       }
	 
      .section-title p {
         font-weight: 300;
         font-size: 12px;
      }
	  
	  .statistics-content > h5 {
        font-size: 20px;
      }
	  
      .statistics-content > span {
        font-size: 10px;
      }
	  
      .statistics-icon {
        font-size: 30px;
      }
	  
      .services-section hr {
          width: 35px;
      }
	  
	  .services-section h3 {
          font-size: 12px;
      }

      .services-section .services-detail {
          width: 180px;
          height: 180px;
      }

      .services-section .services-detail i {
          font-size: 30px;
          margin-top: 45px;
      }
	  
      .owl-theme .owl-controls .owl-buttons div {
          padding: 6px 10px;
          width: 40px;
          height: 40px;
          line-height: 36px;
		  font-size: 8px;
       }
	   
      .contact-us-detail {
          left: 30%;
       }
}


@media only screen and (max-width: 500px) {
	.experience {
		margin-left: 0px;
		border: 0px;
	}
	
	.experience-circle {
		margin: 0 auto;
		position: static;
		margin-bottom: 20px;
	}
	
	.experience-content {
		padding: 10px 15px;
		margin-left: 0px;
		text-align: center;
	}
	
	.experience-content:after, 
	.experience-content:before {
		display: none;
	}
}


@media only screen and (max-width: 449px) {
	   .button {
		   font-size: 13px;
		   padding: 14px 28px;
		   font-weight: 600;
	   }
	   
	   .contact-us-detail {
          left: 25%;
       }
}



/* Useful Classes */


/* Spacing ( with Margin and Padding ) */

/* Margin */

.margin-0 {
	margin: 0px !important;
}

/* Margin Top */

.margin-top-0 {
	margin-top: 0px !important;
}

.margin-top-10 {
	margin-top: 10px !important;
}

.margin-top-20 {
	margin-top: 20px !important;
}

.margin-top-30 {
	margin-top: 30px !important;
}

.margin-top-40 {
	margin-top: 40px !important;
}

.margin-top-50 {
	margin-top: 50px !important;
}

.margin-top-60 {
	margin-top: 60px !important;
}

.margin-top-70 {
	margin-top: 70px !important;
}

.margin-top-80 {
	margin-top: 80px !important;
}

.margin-top-90 {
	margin-top: 90px !important;
}

.margin-top-100 {
	margin-top: 100px !important;
}

.margin-top-120 {
	margin-top: 120px !important;
}

.margin-top-150 {
	margin-top: 150px !important;
}

.margin-top-200 {
	margin-top: 200px !important;
}


/* Margin Bottom */

.margin-bottom-0 {
	margin-bottom: 0px !important;
}

.margin-bottom-10 {
	margin-bottom: 10px !important;
}

.margin-bottom-20 {
	margin-bottom: 20px !important;
}

.margin-bottom-30 {
	margin-bottom: 30px !important;
}

.margin-bottom-40 {
	margin-bottom: 40px !important;
}

.margin-bottom-50 {
	margin-bottom: 50px !important;
}

.margin-bottom-60 {
	margin-bottom: 60px !important;
}

.margin-bottom-70 {
	margin-bottom: 70px !important;
}

.margin-bottom-80 {
	margin-bottom: 80px !important;
}

.margin-bottom-90 {
	margin-bottom: 90px !important;
}

.margin-bottom-100 {
	margin-bottom: 100px !important;
}

.margin-bottom-120 {
	margin-bottom: 120px !important;
}

.margin-bottom-150 {
	margin-bottom: 150px !important;
}

.margin-bottom-200 {
	margin-bottom: 200px !important;
}



/* Padding */

.padding-0 {
	padding: 0px !important;
}


/* Padding Top */

.padding-top-0 {
	padding-top: 0px !important;
}

.padding-top-10 {
	padding-top: 10px !important;
}

.padding-top-20 {
	padding-top: 20px !important;
}

.padding-top-30 {
	padding-top: 30px !important;
}

.padding-top-40 {
	padding-top: 40px !important;
}

.padding-top-50 {
	padding-top: 50px !important;
}

.padding-top-60 {
	padding-top: 60px !important;
}

.padding-top-70 {
	padding-top: 70px !important;
}

.padding-top-80 {
	padding-top: 80px !important;
}

.padding-top-90 {
	padding-top: 90px !important;
}

.padding-top-100 {
	padding-top: 100px !important;
}

.padding-top-120 {
	padding-top: 120px !important;
}

.padding-top-150 {
	padding-top: 150px !important;
}

.padding-top-200 {
	padding-top: 200px !important;
}


/* Padding Bottom */

.padding-bottom-0 {
	padding-bottom: 0px !important;
}

.padding-bottom-10 {
	padding-bottom: 10px !important;
}

.padding-bottom-20 {
	padding-bottom: 20px !important;
}

.padding-bottom-30 {
	padding-bottom: 30px !important;
}

.padding-bottom-40 {
	padding-bottom: 40px !important;
}

.padding-bottom-50 {
	padding-bottom: 50px !important;
}

.padding-bottom-60 {
	padding-bottom: 60px !important;
}

.padding-bottom-70 {
	padding-bottom: 70px !important;
}

.padding-bottom-80 {
	padding-bottom: 80px !important;
}

.padding-bottom-90 {
	padding-bottom: 90px !important;
}

.padding-bottom-100 {
	padding-bottom: 100px !important;
}

.padding-bottom-120 {
	padding-bottom: 120px !important;
}

.padding-bottom-150 {
	padding-bottom: 150px !important;
}

.padding-bottom-200 {
	padding-bottom: 200px !important;
}



/* Colors */

.color-1 {
	color: #f306a0;
}

.color-2 {
	color: #d60bfb;
}

.color-3 {
	color: #d8be10;
}

.color-4 {
	color: #0fd28a;
}

.color-5 {
	color: #f97400;
}

.color-6 {
	color: #08a6f3;
}



/* Background Color */

.bg-color-1 {
	background-color: #f306a0;
}

.bg-color-2 {
	background-color: #d60bfb;
}

.bg-color-3 {
	background-color: #d8be10;
}

.bg-color-4 {
	background-color: #0fd28a;
}

.bg-color-5 {
	background-color: #f97400;
}

.bg-color-6 {
	background-color: #08a6f3;
}



/* Tooltip Styles */

.tooltip-inner {
	font-style: italic;
	padding: 10px 12px;
	min-width: 150px;
	width: 100%;
}

.tooltip.top {
	margin-top:-15px;
}

.tooltip.bottom {
	margin-top:15px;
	bottom: auto;
	left: auto;
	right: auto;
}

.tooltip.left {
	margin-right:15px;
}

.tooltip.right {
	margin-left:15px;
}

.tooltip-color .tooltip-inner {
	color: #fff;
}



/* UiPasta Credit */

.uipasta-credit {
	color: #333333;
	text-align: center;
}

.uipasta-credit a {
	color: #4c9cef;
	font-weight: 600;
}

.uipasta-credit a:hover {
	color: #f7639a;
}

<div class="header-top-area">
            <div class="container">
                <div class="row">
                
                    <div class="col-sm-3">
                        <div class="logo">
                            <a href="index-2.html">WebRes</a>
                        </div>
                    </div>
                    
                    <div class="col-sm-9">
                        <div class="navigation-menu">
                            <div class="navbar">
                                <div class="navbar-header">
                                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                                        <span class="sr-only">Toggle navigation</span>
                                        <span class="icon-bar"></span>
                                        <span class="icon-bar"></span>
                                        <span class="icon-bar"></span>
                                    </button>
                                </div>
                                <div id="menu" class="navbar-collapse collapse">
                                    <ul class="nav navbar-nav navbar-right">
                                        <li class="active"><a class="smoth-scroll" href="#home">Home <div class="ripple-wrapper"></div></a>
                                        </li>
                                        <li><a class="smoth-scroll" href="#about">About</a>
                                        </li>
                                        <li><a class="smoth-scroll" href="#portfolio">Portfolio</a>
                                        </li>
                                        <li><a class="smoth-scroll" href="#testimonials">Testimonial</a>
                                        </li>
                                        <li><a class="smoth-scroll" href="#services">services</a>
                                        </li>
                                        <li><a class="smoth-scroll" href="#contact">Contact</a>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
&#13;
&#13;
&#13;

Here is the image of sample where I need to highlight menu during scroll

1 个答案:

答案 0 :(得分:1)

对于您拥有的每个页面,请在Home.php

中指定变量

位于页面顶部

<?php $page = "home" ?>

然后在导航/工具栏中

<li class=" <?php if($page == "home"){echo "active";}?> "> Home </li>

在您的css文件中,您可以使用活动

自定义所需的任何样式
相关问题