Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixed header jump after using css transition

Tags:

html

jquery

css

I have a problem with fixed header after using transition, it jumps in all browsers especially in Mozilla. I have added jquery scroll function and added class fixed-hd to achieve this. I try to remove transition from header and it work but when I put transition back in the code it start to jump on mouse scroll up and down. Anyone know where is the problem, thanks in advance

Jquery code:

$(document).ready(function() {
    $(window).scroll(function() {
      if ($(window).scrollTop() > 50) {
        $('.header').addClass('fixed-hd');
        } 
        else 
        {
        $('.header').removeClass('fixed-hd');
      }
    });
    });

.header-section {
    width: 100%;
    height: 667px;
    background: url(../images/bg_img.png) repeat-x;
}

.header {
    width: 100%;
    position: relative;
    top: 40px;
    -webkit-transition: all .7s ease-in-out;
    -moz-transition: all .7s ease-in-out;
    -ms-transition: all .7s ease-in-out;
    -o-transition: all .7s ease-in-out;
    transition: all .7s ease-in-out;
}

.hd-fxd {
    width: 1280px;
    height: 60px;
    margin: 0 auto;
}

.logo {
    width: 640px;
    height: 60px;
    float: left;
    position: relative;
}

.logo a {
    position: absolute;
    top: 17px;
    left: 20px;
    color: #fff;
    font-weight: bold;
    font-size: 1.6em;
}

.nav-menu {
    width: 640px;
    height: 60px;
    float: left;
}

.nav-menu ul {
    width: 640px;
    height: 60px;
    background: #53706f;
    text-align: center;
}

.nav-menu ul li {
    display: inline-block;
    height: 60px;
    line-height: 60px;
}

.nav-menu ul li:hover {
    background: #587373;
}

.nav-menu ul li a {
    width: 120px;
    font-size: 17px;
    color: #fff;
    display: block;
}

.fixed-hd {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    margin: 0 auto;
    height: 60px;
    background: #53706f;
}

.section {
    height: 1000px;
}
<div class="header-section">
	<div class="header-wrapper">
		<div class="header">
			<div class="hd-fxd">
				<div class="logo">
					<a href="#">Extreme</a>
				</div><!-- end logo !-->
				<div class="nav-menu">
					<ul>
						<li><a href="#">Home</a></li>
						<li><a href="#">About</a></li>
						<li><a href="#">Portfolio</a></li>
						<li><a href="#">Contact</a></li>
					</ul><!-- end ul !-->
				</div><!-- end nav-menu !-->
			</div><!-- end hd-fxd !-->
		</div><!-- end header !-->
	</div><!-- end header-wrapper !-->
</div><!-- end header-section !-->

<div class="section">
</div>
like image 704
mbole87 Avatar asked Jun 20 '26 19:06

mbole87


2 Answers

DEMO

Changed the header from position: relative; to position: fixed;. This makes the header transition properly.

like image 171
Persijn Avatar answered Jun 23 '26 09:06

Persijn


Try this css

  body{
            padding: 0;
            margin: 0;
        }
        .header-section {
            width: 100%;
            height: 667px;
            background: url(../images/bg_img.png) repeat-x;
        }

        .header {
            width: 100%;
            position: relative;
            top: 40px;
            -webkit-transition: all .7s ease-in-out;
            -moz-transition: all .7s ease-in-out;
            -ms-transition: all .7s ease-in-out;
            -o-transition: all .7s ease-in-out;
            transition: all .7s ease-in-out;
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
        }

        .hd-fxd {
            width: 1280px;
            height: 60px;
            margin: 0 auto;
        }

        .logo {
            width: 640px;
            height: 60px;
            float: left;
            position: relative;
        }

        .logo a {
            position: absolute;
            top: 17px;
            left: 20px;
            color: #fff;
            font-weight: bold;
            font-size: 1.6em;
        }

        .nav-menu {
            width: 640px;
            height: 60px;
            float: left;
        }

        .nav-menu ul {
            width: 640px;
            height: 60px;
            background: #53706f;
            text-align: center;
            margin: 0;
            padding: 0;
        }

        .nav-menu ul li {
            display: inline-block;
            height: 60px;
            line-height: 60px;
        }

        .nav-menu ul li:hover {
            background: #587373;
        }

        .nav-menu ul li a {
            width: 120px;
            font-size: 17px;
            color: #fff;
            display: block;
        }

        .fixed-hd {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            width: 100%;
            margin: 0 auto;
            height: 60px;
            background: #53706f;
        }

        .section {
            height: 1000px;
        }
like image 34
sandun lahiru Avatar answered Jun 23 '26 10:06

sandun lahiru



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!