Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 4 nav side in not smooth/jerky/glitchy

I am trying to get a nice slide in from right with my nav using Bootstrap 4, but is is being really jerky. Here is my code:

var videoWidth = 1280;
    var  video = $(".video-container video").attr("srcdesk");
    if($(window).width() < 721) {
      videoWidth = 720;
      video = $(".video-container video").attr("srcmob");
    }
    $(".video-container video").attr("width", videoWidth).append('<source src="' + video + '" type="video/mp4" >');
a:link {
  color: #ffffff;
  opacity: 60%;
}
a:visited {
  color: #ffffff;
  opacity: 60%;
}
a:hover {
  color: #ffffff;
  opacity: 30%;
}
a:active {
  color: #ffffff;
  opacity: 30%;
}

.video-container {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.video-container video {
    min-width: 100%;
    min-height: 100%;
    width: auto;
    height: auto;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: -2;
}

.logo {
    fill: #ffffff;
    opacity: 60%;
}

.navbar-toggler {
    font-size: 2rem !important;
    color: #ffffff !important;
    opacity: 60% !important;
    border-width: 0px !important;
}

.footer {
    position: absolute;
    bottom: 0;
    width: 98%;
    font-size: 13px;
    height: 25px;
    line-height: 25px;
    /*background-color: #f5f5f5;*/
    margin-left: 1%;
    margin-right: 1%;
    color: #ffffff;
    opacity: 60%;
    text-align: center;
}

.powered{
    float: left;
}
.copy{
    float: center;
}
.reg{
    float: right;
}

@media (max-width: 576px) {
    .navbar-collapse {
        position: absolute;
        top: 0px;
        right: 100%;
        padding-top:  54px;
        padding-left: 15px;
        padding-right: 15px;
        padding-bottom: 0px;
        width: 100%;
        transition: all 0.4s ease;
        display: block;
        height: 100vh;
        width: 20%;
        z-index: -2;
    }
    .navbar-collapse.collapsing {
        height: auto !important;
        margin-left: 0%;
        right: -20%;
        transition: all 0.2s ease;
    }
    .navbar-collapse.show {
        right: 0px;
    }

    .bg-light-sm {
        background-color: #ffffff !important;
        opacity: 90%;
    }

    .navbar-light-sm .navbar-brand {
        color: rgba(0, 0, 0, 0.9);
    }

    .navbar-light-sm .navbar-brand:hover, .navbar-light-sm .navbar-brand:focus {
        color: rgba(0, 0, 0, 0.9);
    }

    .navbar-light-sm .navbar-nav .nav-link {
        color: rgba(0, 0, 0, 0.5);
    }

    .navbar-light-sm .navbar-nav .nav-link:hover, .navbar-light-sm .navbar-nav .nav-link:focus {
        color: rgba(0, 0, 0, 0.7);
    }

    .navbar-light-sm .navbar-nav .nav-link.disabled {
        color: rgba(0, 0, 0, 0.3);
    }

    .navbar-light-sm .navbar-nav .show > .nav-link,
    .navbar-light-sm .navbar-nav .active > .nav-link,
    .navbar-light-sm .navbar-nav .nav-link.show,
    .navbar-light-sm .navbar-nav .nav-link.active {
        color: rgba(0, 0, 0, 0.9);
    }

    .navbar-light-sm .navbar-toggler {
        color: rgba(0, 0, 0, 0.5);
        border-color: rgba(0, 0, 0, 0.1);
    }

    .navbar-light-sm .navbar-toggler-icon {
        background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='30' height='30' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%280, 0, 0, 0.5%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
    }

    .navbar-light-sm .navbar-text {
        color: rgba(0, 0, 0, 0.5);
    }

    .navbar-light-sm .navbar-text a {
        color: rgba(0, 0, 0, 0.9);
    }

    .navbar-light-sm .navbar-text a:hover, .navbar-light-sm .navbar-text a:focus {
        color: rgba(0, 0, 0, 0.9);
    }

    .footer {
    font-size: 10px;
}

    
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>

<div class="video-container">
	<video autoplay loop="true" width="1280" height="720" muted playsinline srcdesk="https://www.corseestrada.com/site/templates/video/video.mp4" srcmob="https://www.corseestrada.com/site/templates/video/video-mobile.mp4"></video>
</div>

<nav class="navbar navbar-expand-sm">
	<a class="navbar-brand" href="#">logo</a>
	<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#menu" aria-controls="menu" aria-expanded="false" aria-label="Toggle navigation">
		<i class="fa fa-bars"></i>
	</button>

	<div class="collapse navbar-collapse justify-content-end navbar-light-sm bg-light-sm" id="menu">
		<ul class="navbar-nav">
			<li class="nav-item">
				<a class="nav-link" href="#">Home</a>
			</li>
			<li class="nav-item">
				<a class="nav-link" href="#">Menu</a>
			</li>
			<li class="nav-item">
				<a class="nav-link">Delivery</a>
			</li>
			<li class="nav-item">
				<a class="nav-link" href="#">Contact</a>
			</li>
		</ul>



	</div>
</nav>

<footer class="footer">

</footer>

I'm pretty sure it has to do with this code right here:

.navbar-collapse.collapsing {
    height: auto !important;
    margin-left: 0%;
    right: -20%;
    transition: all 0.2s ease;
}

To replicate the problem, click "run code snippet" and then resize window to a width < 567px.

Edit: Another problem I have, is when the navigation is out on my iPhone (but not testing in macOS Safari or Chrome) there is a substantial overhang. I need to reduce height: 100vh; to 87 for it not to mess up. Any solutions for that as well?

Thank you!

like image 556
tony Avatar asked Jun 10 '20 05:06

tony


1 Answers

You needed position: fixed; and height: 100% !important; in .collapsing:

@media (max-width: 576px)
.navbar-collapse.collapsing {
    margin-left: 0%;
    right: -20%;
    transition: all 0.2s ease;
    position: fixed;
    height: 100% !important;
}

and you need to remove position: absolute; from video-container as it does not appear to do anything.


For your IOS problem, you can specify your css to the device (credit to https://stackoverflow.com/a/47818418/4101210).

@supports (-webkit-touch-callout: none) {
  /* CSS specific to iOS devices */ 
}

@supports not (-webkit-touch-callout: none) {
  /* CSS for other than iOS devices */ 
}

var videoWidth = 1280;
    var  video = $(".video-container video").attr("srcdesk");
    if($(window).width() < 721) {
      videoWidth = 720;
      video = $(".video-container video").attr("srcmob");
    }
    $(".video-container video").attr("width", videoWidth).append('<source src="' + video + '" type="video/mp4" >');
a:link {
  color: #ffffff;
  opacity: 60%;
}
a:visited {
  color: #ffffff;
  opacity: 60%;
}
a:hover {
  color: #ffffff;
  opacity: 30%;
}
a:active {
  color: #ffffff;
  opacity: 30%;
}

.video-container {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.video-container video {
    min-width: 100%;
    min-height: 100%;
    width: auto;
    height: auto;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: -2;
}

.logo {
    fill: #ffffff;
    opacity: 60%;
}

.navbar-toggler {
    font-size: 2rem !important;
    color: #ffffff !important;
    opacity: 60% !important;
    border-width: 0px !important;
}

.footer {
    position: absolute;
    bottom: 0;
    width: 98%;
    font-size: 13px;
    height: 25px;
    line-height: 25px;
    /*background-color: #f5f5f5;*/
    margin-left: 1%;
    margin-right: 1%;
    color: #ffffff;
    opacity: 60%;
    text-align: center;
}

.powered{
    float: left;
}
.copy{
    float: center;
}
.reg{
    float: right;
}

@media (max-width: 576px) {
    .navbar-collapse {
        position: absolute;
        top: 0px;
        right: 100%;
        padding-top:  54px;
        padding-left: 15px;
        padding-right: 15px;
        padding-bottom: 0px;
        width: 100%;
        transition: all 0.4s ease;
        display: block;
        height: 100vh;
        width: 20%;
        z-index: -2;
    }
    .navbar-collapse.collapsing {
        position: fixed;
        height: 100% !important;
        margin-left: 0%;
        right: -20%;
        transition: all 0.2s ease;
    }
    .navbar-collapse.show {
        right: 0px;
    }

    .bg-light-sm {
        background-color: #ffffff !important;
        opacity: 90%;
    }

    .navbar-light-sm .navbar-brand {
        color: rgba(0, 0, 0, 0.9);
    }

    .navbar-light-sm .navbar-brand:hover, .navbar-light-sm .navbar-brand:focus {
        color: rgba(0, 0, 0, 0.9);
    }

    .navbar-light-sm .navbar-nav .nav-link {
        color: rgba(0, 0, 0, 0.5);
    }

    .navbar-light-sm .navbar-nav .nav-link:hover, .navbar-light-sm .navbar-nav .nav-link:focus {
        color: rgba(0, 0, 0, 0.7);
    }

    .navbar-light-sm .navbar-nav .nav-link.disabled {
        color: rgba(0, 0, 0, 0.3);
    }

    .navbar-light-sm .navbar-nav .show > .nav-link,
    .navbar-light-sm .navbar-nav .active > .nav-link,
    .navbar-light-sm .navbar-nav .nav-link.show,
    .navbar-light-sm .navbar-nav .nav-link.active {
        color: rgba(0, 0, 0, 0.9);
    }

    .navbar-light-sm .navbar-toggler {
        color: rgba(0, 0, 0, 0.5);
        border-color: rgba(0, 0, 0, 0.1);
    }

    .navbar-light-sm .navbar-toggler-icon {
        background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='30' height='30' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%280, 0, 0, 0.5%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
    }

    .navbar-light-sm .navbar-text {
        color: rgba(0, 0, 0, 0.5);
    }

    .navbar-light-sm .navbar-text a {
        color: rgba(0, 0, 0, 0.9);
    }

    .navbar-light-sm .navbar-text a:hover, .navbar-light-sm .navbar-text a:focus {
        color: rgba(0, 0, 0, 0.9);
    }

    .footer {
    font-size: 10px;
}

    
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>

<div class="video-container">
	<video autoplay loop="true" width="1280" height="720" muted playsinline srcdesk="https://www.corseestrada.com/site/templates/video/video.mp4" srcmob="https://www.corseestrada.com/site/templates/video/video-mobile.mp4"></video>
</div>

<nav class="navbar navbar-expand-sm">
	<a class="navbar-brand" href="#">logo</a>
	<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#menu" aria-controls="menu" aria-expanded="false" aria-label="Toggle navigation">
		<i class="fa fa-bars"></i>
	</button>

	<div class="collapse navbar-collapse justify-content-end navbar-light-sm bg-light-sm" id="menu">
		<ul class="navbar-nav">
			<li class="nav-item">
				<a class="nav-link" href="#">Home</a>
			</li>
			<li class="nav-item">
				<a class="nav-link" href="#">Menu</a>
			</li>
			<li class="nav-item">
				<a class="nav-link">Delivery</a>
			</li>
			<li class="nav-item">
				<a class="nav-link" href="#">Contact</a>
			</li>
		</ul>



	</div>
</nav>

<footer class="footer">

</footer>
like image 101
Mech Avatar answered Nov 07 '22 10:11

Mech