cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div id="info_bar">
  <strong>Is Obj in viewport:</strong> <span id="info" style="color:black;"></span>
</div>
 
<div class="content" style="height:1000px;border:1px solid black;">&nbsp;</div>

<div class="content">
    <div id="myObj">Hello World!</div>
  </div>
<div class="content" style="height:1200px;border:1px solid black;">&nbsp;</div>
            
          
!
            
              .content {
	position: relative;
	margin:0 auto;
	padding:2% 0;
	width:90%;
	max-width:1000px;
	height:auto;
	z-index:1;	
	border:0px solid red;
}

#info_bar {
	position:fixed;
	top:0;
	left:0;
	width:100%;
	height:auto;
	padding:30px;
	z-index:9999;
	color:#fff;
	background-color:#9C0;	
}

#myObj {
	width:100%;
	height:auto;
	padding:20px;
	border:1px solid black;
	background-color:#09C;
	color:white;
	font-size:22px;
	opacity:0;
  -webkit-box-sizing: border-box;  
  -moz-box-sizing: border-box;  
  box-sizing: border-box;  
	}
            
          
!
            
              function is_in_viewport(OBJ) // returns true or false
 {  
	 var $OBJ = $(OBJ);
	 var viewportWidth = jQuery(window).width();
   var viewportHeight = jQuery(window).height();

    var documentScrollTop = jQuery(document).scrollTop();
    var documentScrollLeft = jQuery(document).scrollLeft();

    var minTop = documentScrollTop;
    var maxTop = documentScrollTop + viewportHeight;
    var minLeft = documentScrollLeft;
    var maxLeft = documentScrollLeft + viewportWidth;

		OBJ_height = $OBJ.outerHeight();
    var OBJ_Offset = $OBJ.offset();
		OBJ_bottom = OBJ_Offset.top + OBJ_height;
	
	    if (maxTop < OBJ_bottom || minTop > OBJ_bottom ) 
         {return 'No';}
	    else {return 'Yes';} 
  }
  
$(window).scroll(function(){
	$('#info').html(is_in_viewport('#myObj'));
	if(is_in_viewport('#myObj') == 'Yes')
	{$('#myObj').stop().fadeTo( "slow", 1 );}
	else {$('#myObj').stop().fadeTo( "slow", 0);} 
})
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console