Ad

FadeIn() Not Working For A Set Of Divs

- 1 answer

I am looking for three images that I have to fadeIn() and delay(), however they are simply loading like normal. I am unsure of what I am doing wrong. I have their divs set inside of my function and have added a second set of classes inside of each image div class.

Does anyone see what I am doing wrong?

$(function() {
	var oTop = $('#home-img-block-section').offset().top - window.innerHeight;
    $(window).scroll(function(){
    
 		var pTop = $('body').scrollTop();
    	console.log( pTop + ' - ' + oTop );
 		if( pTop > oTop ){
     		imgDelays();
 		}
	});
});

function imgDelays(){
	$('.fadeBlock1').delay(300).fadeIn(300);
	$('.fadeBlock2').delay(800).fadeIn(300);
	$('.fadeBlock2').delay(1300).fadeIn(300);
};

//Image resizing
$('.home-img-block img').addClass(function() {
  return (this.width / this.height > 1) ? 'wide' : 'tall';
});
#home-img-block-section {
  width: 100%;
  height: 900px;
}
#home-img-blocks {
  width: 100%;
  height: 750px;
}
.home-img-block {
  width: 33.33%;
  float: left;
  display: inline-block;
  overflow: hidden;
  cursor: pointer;
  position: relative;
}
.home-img-container {
  position: relative;
  overflow: hidden;
}
.home-img-block:hover .overlay {
  background: rgba(0, 0, 0, 0.6);
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}
.home-img-container:after {
  content: attr(data-content);
  color: #fff;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: all 0.5s;
  border: 1px solid #fff;
  padding: 20px 25px;
  text-align: center;
}
.home-img-container:hover:after {
  opacity: 1;
}
.home-img-block img {
  display: block;
  transition: all 1s ease;
}
.home-img-block:hover img {
  transform: scale(1.25);
  background: rgba(0, 0, 0, 0.3);
  width: 33.33%;
  max-height: 100%;
  overflow: hidden;
}
.home-img-block img.wide {
  max-width: 100%;
  max-height: 100%;
  height: auto;
  width: 100%;
}
.home-img-block img.tall {
  max-width: 100%;
  max-height: 100%;
  width: auto;
}
#home-img-block-wording-container {
  width: 100%;
  height: 300px;
}
.home-img-wording-blocks {
  width: 100%;
  height: 100%;
  text-align: center;
  display: inline-block;
  vertical-align: top;
}
.home-img-wording-block-title {
  padding-top: 30px;
  font-size: 1.7em;
}
.home-img-wording-block-description {
  padding: 25px 50px 0 50px;
  font-size: 1.1em;
  color: #5d5d5d;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>    <div id="home-img-block-section">
	  <div id="home-img-blocks">
		<div class="home-img-block fadeBlock1">
		  <div data-content="FIND OUT MORE" class='home-img-container'>
			<img src="http://optimumwebdesigns.com/images/test1.jpg">
			<div class="overlay"></div>
		  </div>
		  <div class="home-img-wording-blocks">
			<div class="home-img-wording-block-title">WEB DESIGN</div>
			<div class="home-img-wording-block-description">The OD team can see your web design visions brought to life, creating a site that promotes your uniqueness through specific functionalities and features.</div>
		  </div>
		</div>
		<div class="home-img-block fadeBlock2">
		  <div data-content="FIND OUT MORE" class='home-img-container'>
			<img src="http://optimumwebdesigns.com/images/test2new.jpg">
			<div class="overlay"></div>
		  </div>
		  <div class="home-img-wording-blocks">
			<div class="home-img-wording-block-title">ECOMMERCE</div>
			<div class="home-img-wording-block-description">Custom built solutions catered towards you end goal.</div>
		  </div>
		</div>
		<div class="home-img-block fadeBlock3">
		  <div data-content="FIND OUT MORE" class='home-img-container'>
			<img src="http://optimumwebdesigns.com/images/test3new.jpg">
			<div class="overlay"></div>
		  </div>
		  <div class="home-img-wording-blocks">
			<div class="home-img-wording-block-title">MARKETING STRATEGIES</div>
			<div class="home-img-wording-block-description">MARKETING STRATEGIES</div>
		  </div>
		</div>
	  </div>
	</div>

Ad

Answer

What's the $(window).scroll function supposed to do? If you just want the images to fade in when the page loads, then just call your imgDelays() function in the document.ready function like this: Oh, and set your .home-img-block class to display: none initially.

$(function() {
  
  imgDelays();

});

function imgDelays(){
	$('.fadeBlock1').delay(300).fadeIn(300);
	$('.fadeBlock2').delay(800).fadeIn(300);
	$('.fadeBlock3').delay(1300).fadeIn(300);
};

//Image resizing
$('.home-img-block img').addClass(function() {
  return (this.width / this.height > 1) ? 'wide' : 'tall';
});
#home-img-block-section {
  width: 100%;
  height: 900px;
}
#home-img-blocks {
  width: 100%;
  height: 750px;
}
.home-img-block {
  width: 33.33%;
  float: left;
  display: none;
  overflow: hidden;
  cursor: pointer;
  position: relative;
}
.home-img-container {
  position: relative;
  overflow: hidden;
}
.home-img-block:hover .overlay {
  background: rgba(0, 0, 0, 0.6);
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}
.home-img-container:after {
  content: attr(data-content);
  color: #fff;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: all 0.5s;
  border: 1px solid #fff;
  padding: 20px 25px;
  text-align: center;
}
.home-img-container:hover:after {
  opacity: 1;
}
.home-img-block img {
  display: block;
  transition: all 1s ease;
}
.home-img-block:hover img {
  transform: scale(1.25);
  background: rgba(0, 0, 0, 0.3);
  width: 33.33%;
  max-height: 100%;
  overflow: hidden;
}
.home-img-block img.wide {
  max-width: 100%;
  max-height: 100%;
  height: auto;
  width: 100%;
}
.home-img-block img.tall {
  max-width: 100%;
  max-height: 100%;
  width: auto;
}
#home-img-block-wording-container {
  width: 100%;
  height: 300px;
}
.home-img-wording-blocks {
  width: 100%;
  height: 100%;
  text-align: center;
  display: inline-block;
  vertical-align: top;
}
.home-img-wording-block-title {
  padding-top: 30px;
  font-size: 1.7em;
}
.home-img-wording-block-description {
  padding: 25px 50px 0 50px;
  font-size: 1.1em;
  color: #5d5d5d;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>    <div id="home-img-block-section">
	  <div id="home-img-blocks">
		<div class="home-img-block fadeBlock1">
		  <div data-content="FIND OUT MORE" class='home-img-container'>
			<img src="http://optimumwebdesigns.com/images/test1.jpg">
			<div class="overlay"></div>
		  </div>
		  <div class="home-img-wording-blocks">
			<div class="home-img-wording-block-title">WEB DESIGN</div>
			<div class="home-img-wording-block-description">The OD team can see your web design visions brought to life, creating a site that promotes your uniqueness through specific functionalities and features.</div>
		  </div>
		</div>
		<div class="home-img-block fadeBlock2">
		  <div data-content="FIND OUT MORE" class='home-img-container'>
			<img src="http://optimumwebdesigns.com/images/test2new.jpg">
			<div class="overlay"></div>
		  </div>
		  <div class="home-img-wording-blocks">
			<div class="home-img-wording-block-title">ECOMMERCE</div>
			<div class="home-img-wording-block-description">Custom built solutions catered towards you end goal.</div>
		  </div>
		</div>
		<div class="home-img-block fadeBlock3">
		  <div data-content="FIND OUT MORE" class='home-img-container'>
			<img src="http://optimumwebdesigns.com/images/test3new.jpg">
			<div class="overlay"></div>
		  </div>
		  <div class="home-img-wording-blocks">
			<div class="home-img-wording-block-title">MARKETING STRATEGIES</div>
			<div class="home-img-wording-block-description">MARKETING STRATEGIES</div>
		  </div>
		</div>
	  </div>
	</div>

Ad
source: stackoverflow.com
Ad