fadeIn()不适用于一组div

时间:2016-01-23 01:28:57

标签: javascript jquery html css image

我正在寻找我需要fadeIn()delay()的三张图片,但它们只是像平常一样加载。我不确定我做错了什么。我在我的函数中设置了div,并在每个图像div类中添加了第二组类。

有人看到我做错了吗?



$(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>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

$(window).scroll函数应该做什么? 如果您只是希望图片在页面加载时淡入,那么只需在document.ready函数中调用imgDelays()函数,如下所示: 哦,最初将.home-img-block课程设为display: none

$(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>