Scroll to view if element partially out of view port height

Developer
Size
2,104 Kb
Views
38,456

How do I make an scroll to view if element partially out of view port height?

Elment scrolls into view if element outside of viewport height.. What is a scroll to view if element partially out of view port height? How do you make a scroll to view if element partially out of view port height? This script and codes were developed by Chris Maki on 12 August 2022, Friday.

Scroll to view if element partially out of view port height Previews

Scroll to view if element partially out of view port height - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>scroll to view if element partially out of view port height</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="container">
<div>this is some stuff</div>
<section>this is some more stuff</section>
<div class="last">this is some more stuuff</div> <button>tester butt</button> <div class="tester"></div> </div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Scroll to view if element partially out of view port height - Script Codes CSS Codes

.container{ width: 350px; margin:30px auto;
}
/* section {padding-bottom: 2000px;} */
.last{ height: 250px; width: 250px; background-color: gray; margin-bottom: 20px
}
.round {border-radius: 50%}
.tester { height: 250px; margin-top: 50px; width: 250px; background-color: black; display: none}

Scroll to view if element partially out of view port height - Script Codes JS Codes

 function checkHeight(el){
var viewportHeight = jQuery(window).height();
var documentScrollTop = jQuery(document).scrollTop();
var minTop = documentScrollTop;
var maxTop = documentScrollTop + viewportHeight;
var myElement = jQuery(el);
var elementOffset = myElement.offset();
var elementHeight = myElement.height();
if (elementOffset.top > minTop && elementOffset.top + elementHeight > maxTop) {jQuery('html,body').animate({scrollTop: 350}, 1500);}
}
//checkHeight('.tester');
function open(){
$('button').on('click', function(){ $('.tester').slideToggle(); checkHeight('.tester');
});
}open();
Scroll to view if element partially out of view port height - Script Codes
Scroll to view if element partially out of view port height - Script Codes
Home Page Home
Developer Chris Maki
Username chrisMaki
Uploaded August 12, 2022
Rating 3
Size 2,104 Kb
Views 38,456
Do you need developer help for Scroll to view if element partially out of view port height?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Chris Maki (chrisMaki) Script Codes
Create amazing marketing copy with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!