âšī¸ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0.1 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://infoheap.com/jquery-check-if-element-is-visible-in-viewport/ |
| Last Crawled | 2026-04-12 07:12:26 (3 days ago) |
| First Indexed | 2021-11-26 06:57:01 (4 years ago) |
| HTTP Status Code | 200 |
| Meta Title | jQuery - check if element is visible in viewport ofter scroll - InfoHeap |
| Meta Description | How to make a div stick at top when a page is scrolled down by manipulating css position propery of div in jQuery - InfoHeap - Tech |
| Meta Canonical | null |
| Boilerpipe Text | Home
>
Tutorials
>
Javascript
>
jQuery
To check if an element is visible in window viewport after vertical scrolling the following approach can be used using jQuery. Note that this approach assumes that there is no horizontal scrolling. Similar approach can be applied to check visibility in case there is horizontal scrolling.
Window top can be obtained using
$(window).scrollTop()
and height can be obtained using
$(window).height()
.
Similarly element top can be obtained using
$(el).offset().top
and its height can be obtained using
$(el).height()
.
Example
Here is the outcome screenshot and code to check if an element is visible in window viewport.
<style>.largebox {height: 800px;}</style>
<div id="msg" style="position:fixed;left:30%;"></div>
<div id="box1" class="box">box1</div>
<div class="largebox">box2</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
function isVisible($el) {
var winTop = $(window).scrollTop();
var winBottom = winTop + $(window).height();
var elTop = $el.offset().top;
var elBottom = elTop + $el.height();
return ((elBottom<= winBottom) && (elTop >= winTop));
}
$(function() {
$("#msg").text("#box1 visible=" + isVisible($("#box1")));
$(window).scroll(function() {
$("#msg").text("#box1 visible=" + isVisible($("#box1")));
});
});
</script>
Share this article: |
| Markdown | [](https://infoheap.com/tech/ "InfoHeap")
Tech
Navigation
- [Home](https://infoheap.com/tech/)
- [Tutorials](https://infoheap.com/tutorials/)
- [CSS tutorials & examples](https://infoheap.com/topic/css/)
- [CSS properties](https://infoheap.com/topic/css-property/)
- [Javascript cookbook](https://infoheap.com/topic/javascript-cookbook/)
- [Linux/Unix Command Line](https://infoheap.com/topic/command-line/)
- [Mac](https://infoheap.com/topic/mac/)
- [PHP](https://infoheap.com/topic/php/)
- [PHP functions online](https://infoheap.com/topic/php-functions-online/)
- [PHP regex](https://infoheap.com/topic/php-regex/)
- [WordPress](https://infoheap.com/topic/wordpress/)
- [Online Tools](https://infoheap.com/tool/)
- [Text utilities](https://infoheap.com/topic/string-utilities/)
- [Online Lint Tools](https://infoheap.com/topic/lint/)


## jQuery tutorials
### jQuery Ajax
- [jQuery JSONP](https://infoheap.com/jquery-jsonp-cross-domain-ajax/)
- [jQuery .post()](https://infoheap.com/jquery-post/)
- [jQuery .load()](https://infoheap.com/jquery-ajax-load/)
- [load script with cache enabled](https://infoheap.com/jquery-load-script-with-cache-enabled/)
- [jQuery .ajax() file upload](https://infoheap.com/jquery-ajax-post-a-form-having-file-uploads/)
### jQuery CSS
- [change table cells color based on value](https://infoheap.com/jquery-change-table-cells-color-based-on-values/)
- [check if element is visible in viewport](https://infoheap.com/jquery-check-if-element-is-visible-in-viewport/)
- [display auto fade out message](https://infoheap.com/jquery-display-auto-fade-out-message/)
- [fitvids.js for automatically resizing videos](https://infoheap.com/fitvids-fluid-width-videos/)
- [get class list of an element](https://infoheap.com/jquery-get-class-list/)
- [jQuery toggleClass() examples](https://infoheap.com/jquery-toggleclass/)
- [make a div stick at top on scroll](https://infoheap.com/jquery-make-a-div-stick-at-top-on-scroll/)
- [table with alternate color rows](https://infoheap.com/html-table-with-alternate-color-rows/)
### jQuery Events
- [Javascript/jQuery - disable right click](https://infoheap.com/javascript-jquery-disable-right-click/)
- [jQuery - text input field - change keyup and paste events](https://infoheap.com/jquery-text-input-field-change-keyup-paste-events/)
- [trigger click using jQuery or Javascript](https://infoheap.com/javascript-jquery-trigger-click/)
### jQuery DOM
- [jQuery html() vs text()](https://infoheap.com/jquery-difference-between-html-and-text/)
- [Check if an element exists](https://infoheap.com/jquery-check-if-an-element-exists/)
- [find total DOM elements](https://infoheap.com/jquery-total-number-of-dom-elements/)
- [jQuery encode string to html entities](https://infoheap.com/jquery-encode-string-html-entities/)
- [jQuery - read and modify iframe content](https://infoheap.com/jquery-read-modify-iframe-content/)
- [jQuery - create iframe with content](https://infoheap.com/jquery-create-iframe-with-content/)
- [jQuery - find select element selectedIndex, value and text](https://infoheap.com/jquery-select-selected-index-value-and-text/)
- [jQuery - get checkbox value and checked state](https://infoheap.com/jquery-checkbox-value-and-state/)
- [jQuery - get javascript object](https://infoheap.com/jquery-get-javascript-object/)
### jQuery Cookbook
- [get jQuery version](https://infoheap.com/jquery-get-version-info/)
- [jQuery - add text to existing div](https://infoheap.com/jquery-add-text-existing-div/)
- [jQuery sliding effect - slideUp, slideDown, slideToggle](https://infoheap.com/jquery-sliding-effect-slideup-slidedown-slidetoggle/)
### jQuery UI
- [jQuery UI make element movable](https://infoheap.com/jquery-ui-make-element-draggable/)
- [jQuery ui slider and input text box - one way binding](https://infoheap.com/jquery-ui-slider-input-text-box-one-way-binding/)
- [jQuery ui slider and input text box - two way binding](https://infoheap.com/jquery-ui-slider-and-input-text-box-two-way-binding/)
- [Home](https://infoheap.com/tech/ "Home")
- \> [Tutorials](https://infoheap.com/tutorials/ "Tutorials")
- \> [Javascript](https://infoheap.com/topic/javascript/ "Javascript")
- \> [jQuery](https://infoheap.com/topic/jquery/ "jQuery")
# [jQuery â check if element is visible in viewport ofter scroll](https://infoheap.com/jquery-check-if-element-is-visible-in-viewport/)
on
Apr 2, 2016
To check if an element is visible in window viewport after vertical scrolling the following approach can be used using jQuery. Note that this approach assumes that there is no horizontal scrolling. Similar approach can be applied to check visibility in case there is horizontal scrolling.
1. Window top can be obtained using `$(window).scrollTop()` and height can be obtained using `$(window).height()`.
2. Similarly element top can be obtained using `$(el).offset().top` and its height can be obtained using `$(el).height()`.
## Example
Here is the outcome screenshot and code to check if an element is visible in window viewport.

```
<style>.largebox {height: 800px;}</style>
<div id="msg" style="position:fixed;left:30%;"></div>
<div id="box1" class="box">box1</div>
<div class="largebox">box2</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
function isVisible($el) {
var winTop = $(window).scrollTop();
var winBottom = winTop + $(window).height();
var elTop = $el.offset().top;
var elBottom = elTop + $el.height();
return ((elBottom<= winBottom) && (elTop >= winTop));
}
$(function() {
$("#msg").text("#box1 visible=" + isVisible($("#box1")));
$(window).scroll(function() {
$("#msg").text("#box1 visible=" + isVisible($("#box1")));
});
});
</script>
```
[refresh]() done
[try it online](https://infoheap.com/html-js-css-sandbox/code/12276-code1/)
### Suggested posts:
1. [CSS resize â make block element resizable by user](https://infoheap.com/css-resize-property/ "CSS resize â make block element resizable by user")
2. [egrep pipe example on Apache access log](https://infoheap.com/egrep-pipe-example-apache-access-log/ "egrep pipe example on Apache access log")
3. [CSS general sibling selector](https://infoheap.com/css-general-sibling-selector/ "CSS general sibling selector")
4. [Jquery â change table cells color based on value](https://infoheap.com/jquery-change-table-cells-color-based-on-values/ "Jquery â change table cells color based on value")
5. [Vim (vi) â multiline search replace with confirmation](https://infoheap.com/vi-multiline-search-replace-with-confirmation/ "Vim (vi) â multiline search replace with confirmation")
6. [CSS attribute substring selectors](https://infoheap.com/css-attribute-substring-selectors/ "CSS attribute substring selectors")
7. [CSS animation shorthand property](https://infoheap.com/css-animation-property/ "CSS animation shorthand property")
8. [CSS attribute presence and value selectors](https://infoheap.com/css-attribute-selectors/ "CSS attribute presence and value selectors")
Share this article: [](http://www.facebook.com/share.php?u=https%3A%2F%2Finfoheap.com%2Fjquery-check-if-element-is-visible-in-viewport%2F "share on facebook") [](http://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Finfoheap.com%2Fjquery-check-if-element-is-visible-in-viewport%2F&title=jQuery+%E2%80%93+check+if+element+is+visible+in+viewport+ofter+scroll "share on linkedin") [](https://twitter.com/intent/tweet?url=https%3A%2F%2Finfoheap.com%2Fjquery-check-if-element-is-visible-in-viewport%2F&text=jQuery+%E2%80%93+check+if+element+is+visible+in+viewport+ofter+scroll "tweet this") [](http://www.reddit.com/submit?url=https%3A%2F%2Finfoheap.com%2Fjquery-check-if-element-is-visible-in-viewport%2F&title=jQuery+%E2%80%93+check+if+element+is+visible+in+viewport+ofter+scroll "submit to reddit")
Posted in [Tutorials](https://infoheap.com/category/tutorial/) \| Tagged [CSS](https://infoheap.com/topic/css/), [jQuery](https://infoheap.com/topic/jquery/), [Tutorials](https://infoheap.com/topic/tutorials/)
- [Browse content](https://infoheap.com/browse/)
- [Article Topics](https://infoheap.com/cat-list/)
- [Article archives](https://infoheap.com/archives/)
- [Contact Us](https://infoheap.com/contact-us/)
Popular Topics: [Android Development](https://infoheap.com/topic/android-development/ "Android Development") \| [AngularJS](https://infoheap.com/topic/angularjs/ "AngularJS") \| [Apache](https://infoheap.com/topic/apache/ "Apache") \| [AWS and EC2](https://infoheap.com/topic/aws/ "AWS and EC2") \| [Bash shell scripting](https://infoheap.com/topic/bash/ "Bash shell scripting") \| [Chrome developer tools](https://infoheap.com/topic/chrome-developer-tools/ "Chrome developer tools") \| [Company results](https://infoheap.com/topic/company-results/ "Company results") \| [CSS](https://infoheap.com/topic/css/ "CSS") \| [CSS cookbook](https://infoheap.com/topic/css-cookbook/ "CSS cookbook") \| [CSS properties](https://infoheap.com/topic/css-property/ "CSS properties") \| [CSS Pseudo Classes](https://infoheap.com/topic/css-pseudo-classes/ "CSS Pseudo Classes") \| [CSS selectors](https://infoheap.com/topic/css-selector/ "CSS selectors") \| [CSS3](https://infoheap.com/topic/css3/ "CSS3") \| [CSS3 flexbox](https://infoheap.com/topic/css-flexbox/ "CSS3 flexbox") \| [Devops](https://infoheap.com/topic/devops/ "Devops") \| [Git](https://infoheap.com/topic/git/ "Git") \| [HTML](https://infoheap.com/topic/html/ "HTML") \| [HTML5](https://infoheap.com/topic/html5/ "HTML5") \| [Java](https://infoheap.com/topic/java/ "Java") \| [Javascript](https://infoheap.com/topic/javascript/ "Javascript") \| [Javascript cookbook](https://infoheap.com/topic/javascript-cookbook/ "Javascript cookbook") \| [Javascript DOM](https://infoheap.com/topic/javascript-dom/ "Javascript DOM") \| [jQuery](https://infoheap.com/topic/jquery/ "jQuery") \| [Kubernetes](https://infoheap.com/topic/kubernetes/ "Kubernetes") \| [Linux](https://infoheap.com/topic/linux/ "Linux") \| [Linux/Unix Command Line](https://infoheap.com/topic/command-line/ "Linux/Unix Command Line") \| [Mac](https://infoheap.com/topic/mac/ "Mac") \| [Mac Command Line](https://infoheap.com/topic/mac-command-line/ "Mac Command Line") \| [Mysql](https://infoheap.com/topic/mysql/ "Mysql") \| [Networking](https://infoheap.com/topic/networking/ "Networking") \| [Node.js](https://infoheap.com/topic/node-js/ "Node.js") \| [Online Tools](https://infoheap.com/topic/online-tools/ "Online Tools") \| [PHP](https://infoheap.com/topic/php/ "PHP") \| [PHP cookbook](https://infoheap.com/topic/php-cookbook/ "PHP cookbook") \| [PHP Regex](https://infoheap.com/topic/php-regex/ "PHP Regex") \| [Python](https://infoheap.com/topic/python/ "Python") \| [Python array](https://infoheap.com/topic/python-array/ "Python array") \| [Python cookbook](https://infoheap.com/topic/python-cookbook/ "Python cookbook") \| [SEO](https://infoheap.com/topic/seo/ "SEO") \| [Site Performance](https://infoheap.com/topic/site-performance/ "Site Performance") \| [SSH](https://infoheap.com/topic/ssh/ "SSH") \| [Ubuntu Linux](https://infoheap.com/topic/ubuntu/ "Ubuntu Linux") \| [Web Development](https://infoheap.com/topic/web-development/ "Web Development") \| [Webmaster](https://infoheap.com/topic/webmaster/ "Webmaster") \| [Wordpress](https://infoheap.com/topic/wordpress/ "Wordpress") \| [Wordpress customization](https://infoheap.com/topic/wordpress-customization/ "Wordpress customization") \| [Wordpress How To](https://infoheap.com/topic/wordpress-how-to/ "Wordpress How To") \| [Wordpress Mysql Queries](https://infoheap.com/topic/wordpress-mysql-query/ "Wordpress Mysql Queries") \| [InfoHeap Money](https://infoheap.com/) \| [InfoHeap Mutual Funds](https://infoheap.com/mutual-funds/)
Copyright Š 2026 [InfoHeap](https://infoheap.com/ "InfoHeap").
Powered by [WordPress](http://wordpress.org/ "State-of-the-art semantic personal publishing platform") |
| Readable Markdown | - [Home](https://infoheap.com/tech/ "Home")
- \> [Tutorials](https://infoheap.com/tutorials/ "Tutorials")
- \> [Javascript](https://infoheap.com/topic/javascript/ "Javascript")
- \> [jQuery](https://infoheap.com/topic/jquery/ "jQuery")
To check if an element is visible in window viewport after vertical scrolling the following approach can be used using jQuery. Note that this approach assumes that there is no horizontal scrolling. Similar approach can be applied to check visibility in case there is horizontal scrolling.
1. Window top can be obtained using `$(window).scrollTop()` and height can be obtained using `$(window).height()`.
2. Similarly element top can be obtained using `$(el).offset().top` and its height can be obtained using `$(el).height()`.
## Example
Here is the outcome screenshot and code to check if an element is visible in window viewport.

```
<style>.largebox {height: 800px;}</style>
<div id="msg" style="position:fixed;left:30%;"></div>
<div id="box1" class="box">box1</div>
<div class="largebox">box2</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
function isVisible($el) {
var winTop = $(window).scrollTop();
var winBottom = winTop + $(window).height();
var elTop = $el.offset().top;
var elBottom = elTop + $el.height();
return ((elBottom<= winBottom) && (elTop >= winTop));
}
$(function() {
$("#msg").text("#box1 visible=" + isVisible($("#box1")));
$(window).scroll(function() {
$("#msg").text("#box1 visible=" + isVisible($("#box1")));
});
});
</script>
```
Share this article: [](http://www.facebook.com/share.php?u=https%3A%2F%2Finfoheap.com%2Fjquery-check-if-element-is-visible-in-viewport%2F "share on facebook") [](http://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Finfoheap.com%2Fjquery-check-if-element-is-visible-in-viewport%2F&title=jQuery+%E2%80%93+check+if+element+is+visible+in+viewport+ofter+scroll "share on linkedin") [](https://twitter.com/intent/tweet?url=https%3A%2F%2Finfoheap.com%2Fjquery-check-if-element-is-visible-in-viewport%2F&text=jQuery+%E2%80%93+check+if+element+is+visible+in+viewport+ofter+scroll "tweet this") [](http://www.reddit.com/submit?url=https%3A%2F%2Finfoheap.com%2Fjquery-check-if-element-is-visible-in-viewport%2F&title=jQuery+%E2%80%93+check+if+element+is+visible+in+viewport+ofter+scroll "submit to reddit") |
| Shard | 175 (laksa) |
| Root Hash | 12557530982376942175 |
| Unparsed URL | com,infoheap!/jquery-check-if-element-is-visible-in-viewport/ s443 |