我遇到了一些問題,試圖讓我的CSS過渡/序列開始,一旦我滾動其父div。我已經完成了JavaScript功能,只是從來沒有一個CSS過渡。如何獲得一個css過渡,直到滾動到一個特定的div才啓動
現在我的圖片甚至不會顯示,更不用說從序列開始了。如果我註釋掉javascript,那麼序列將正常播放。
當我進入父div section1
時,我該如何獲得css轉換?
我把這個在評論中的jsfiddle,因爲它更容易看到這一點。
/*$("#think").hide();
//init scrolling event heandler
$(document).scroll(function() {
var docScroll = $(document).scrollTop(),
boxCntOfset = $("#section1").offset().top - 100;
//when rich top of boxex than fire
if (docScroll >= boxCntOfset) {
$("#think").fadeIn(200)
} else {
$("#think").fadeOut(200)
}
})*/
//Scroll for think images
/*$("#think").hide();
$(function() {
var oTop = $('##section1').offset().top - window.innerHeight;
$(window).scroll(function() {
var pTop = $('body').scrollTop();
console.log(pTop + ' - ' + oTop);
if (pTop > oTop) {
$("#think").fadeIn(200)
}
});
});*/
#red {
width: 100%;
height: 700px;
background:red;
}
#section1 {
width: 100%;
height: 600px;
background:blue;
}
#think {
/*opacity: 0;*/
\t margin-left: 200px;
\t width: auto;
\t height: 500px;
\t -webkit-animation-name: think;
\t animation-name: think;
\t -webkit-animation-duration: 8s;
\t animation-duration: 8s;
-webkit-animation-direction: normal;
animation-direction: normal;
\t -webkit-animation-fill-mode: forwards;
\t animation-fill-mode: forwards;
\t /*min-height: 500px; min-width: 500px;*/
\t background-repeat: no-repeat;
\t /*background-size: 100% auto;*/
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="red"></div>
<div class="section" id="section1">
<div id="section1-right-container">
<div id="think"></div>
</div>
</div>
https://jsfiddle.net/#&togetherjs=yjijgkGMs3 – Becky
可能重複:http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport/7557433#7557433 – Zach
我不只是試圖弄清楚是否有東西在視口中?我想初始化一些東西?那怎麼樣? – Becky