我需要實現這種動畫效果,例如在this頁面中使用。 我已經嘗試了很多次在互聯網上發現的一切,但沒有一個解決方案像這樣工作,我無法修復它。我想對於懂Javascript的人來說應該很容易(但我不是他們中的一員,這是我第一次需要這樣的東西,我的研究持續了幾個小時,所以我很抱歉,但我試過了問更多的JS有經驗的人)。考慮seo時淡入動畫滾動(但只有一次)
在理想的情況下,它不應該通過隱藏的東西解決,因爲我害怕搜索引擎優化的不良影響。
$(document).ready(function() {
/* Every time the window is scrolled ... */
$(window).scroll(function(){
/* Check the location of each desired element */
$('.hideme').each(function(i){
var bottom_of_object = $(this).offset().top + $(this).outerHeight();
var bottom_of_window = $(window).scrollTop() + $(window).height();
/* If the object is completely visible in the window, fade it it */
if(bottom_of_window+500 > bottom_of_object){
$(this).addClass("slideUp");
$(this).animate({'opacity':'1'});
}
});
});
});
.slideUp{
\t animation-name: slideUp;
\t -webkit-animation-name: slideUp; \t
\t animation-duration: 0.5s; \t
\t -webkit-animation-duration: 0.5s;
\t animation-timing-function: ease-in-out; \t
\t -webkit-animation-timing-function: ease-in-out; \t \t
\t
}
@keyframes slideUp {
\t 0% {
\t \t transform: translateY(5%);
display: none;
opacity: 0;
\t }
100% {
\t \t transform: translateY(0%);
display: block;
opacity: 1;
\t }
\t
}
@-webkit-keyframes slideUp {
\t 0% {
\t \t -webkit-transform: translateY(5%);
-webkit-display: none;
-webkit-opacity: 0;
\t }
\t 100%{
\t \t -webkit-transform: translateY(0%);
-webkit-display: block;
-webkit-opacity: 1;
\t } \t \t \t
}
.red-bg {background-color: red; color: white; padding: 50px; margin-top: 25px;}
.blue-bg {background-color: blue; color: white; padding: 50px; margin-top: 25px;}
.hideme
{
opacity:0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="hideme red-bg">
<p>
Lorem ipsum dolor sit amet sit veroeros sed et blandit consequat sed veroeros lorem et blandit adipiscing feugiat phasellus tempus hendrerit, tortor vitae mattis tempor, sapien sem feugiat sapien, id suscipit magna felis nec elit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos lorem ipsum dolor sit amet.
</p>
<p>
Lorem ipsum dolor sit amet sit veroeros sed et blandit consequat sed veroeros lorem et blandit adipiscing feugiat phasellus tempus hendrerit, tortor vitae mattis tempor, sapien sem feugiat sapien, id suscipit magna felis nec elit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos lorem ipsum dolor sit amet.
</p>
<p>
Lorem ipsum dolor sit amet sit veroeros sed et blandit consequat sed veroeros lorem et blandit adipiscing feugiat phasellus tempus hendrerit, tortor vitae mattis tempor, sapien sem feugiat sapien, id suscipit magna felis nec elit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos lorem ipsum dolor sit amet.
</p>
<p>
Lorem ipsum dolor sit amet sit veroeros sed et blandit consequat sed veroeros lorem et blandit adipiscing feugiat phasellus tempus hendrerit, tortor vitae mattis tempor, sapien sem feugiat sapien, id suscipit magna felis nec elit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos lorem ipsum dolor sit amet.
</p>
<p>
Lorem ipsum dolor sit amet sit veroeros sed et blandit consequat sed veroeros lorem et blandit adipiscing feugiat phasellus tempus hendrerit, tortor vitae mattis tempor, sapien sem feugiat sapien, id suscipit magna felis nec elit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos lorem ipsum dolor sit amet.
</p>
</div>
<div class="hideme blue-bg">
<p>
Lorem ipsum dolor sit amet sit veroeros sed et blandit consequat sed veroeros lorem et blandit adipiscing feugiat phasellus tempus hendrerit, tortor vitae mattis tempor, sapien sem feugiat sapien, id suscipit magna felis nec elit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos lorem ipsum dolor sit amet.
</p>
<p>
Lorem ipsum dolor sit amet sit veroeros sed et blandit consequat sed veroeros lorem et blandit adipiscing feugiat phasellus tempus hendrerit, tortor vitae mattis tempor, sapien sem feugiat sapien, id suscipit magna felis nec elit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos lorem ipsum dolor sit amet.
</p>
<p>
Lorem ipsum dolor sit amet sit veroeros sed et blandit consequat sed veroeros lorem et blandit adipiscing feugiat phasellus tempus hendrerit, tortor vitae mattis tempor, sapien sem feugiat sapien, id suscipit magna felis nec elit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos lorem ipsum dolor sit amet.
</p>
<p>
Lorem ipsum dolor sit amet sit veroeros sed et blandit consequat sed veroeros lorem et blandit adipiscing feugiat phasellus tempus hendrerit, tortor vitae mattis tempor, sapien sem feugiat sapien, id suscipit magna felis nec elit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos lorem ipsum dolor sit amet.
</p>
<p>
Lorem ipsum dolor sit amet sit veroeros sed et blandit consequat sed veroeros lorem et blandit adipiscing feugiat phasellus tempus hendrerit, tortor vitae mattis tempor, sapien sem feugiat sapien, id suscipit magna felis nec elit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos lorem ipsum dolor sit amet.
</p>
</div>
<div class="hideme red-bg">
<p>
Lorem ipsum dolor sit amet sit veroeros sed et blandit consequat sed veroeros lorem et blandit adipiscing feugiat phasellus tempus hendrerit, tortor vitae mattis tempor, sapien sem feugiat sapien, id suscipit magna felis nec elit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos lorem ipsum dolor sit amet.
</p>
<p>
Lorem ipsum dolor sit amet sit veroeros sed et blandit consequat sed veroeros lorem et blandit adipiscing feugiat phasellus tempus hendrerit, tortor vitae mattis tempor, sapien sem feugiat sapien, id suscipit magna felis nec elit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos lorem ipsum dolor sit amet.
</p>
<p>
Lorem ipsum dolor sit amet sit veroeros sed et blandit consequat sed veroeros lorem et blandit adipiscing feugiat phasellus tempus hendrerit, tortor vitae mattis tempor, sapien sem feugiat sapien, id suscipit magna felis nec elit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos lorem ipsum dolor sit amet.
</p>
<p>
Lorem ipsum dolor sit amet sit veroeros sed et blandit consequat sed veroeros lorem et blandit adipiscing feugiat phasellus tempus hendrerit, tortor vitae mattis tempor, sapien sem feugiat sapien, id suscipit magna felis nec elit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos lorem ipsum dolor sit amet.
</p>
<p>
Lorem ipsum dolor sit amet sit veroeros sed et blandit consequat sed veroeros lorem et blandit adipiscing feugiat phasellus tempus hendrerit, tortor vitae mattis tempor, sapien sem feugiat sapien, id suscipit magna felis nec elit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos lorem ipsum dolor sit amet.
</p>
</div>
謝謝大家的幫助。
你可以添加你有問題的代碼嗎?看看[問]和[mcve] –
@TimHutchison我得到的最接近的是這個:https://jsfiddle.net/g2wLgz7c/(我問了一下之後,我取得了一些進展,但仍然覺得我的代碼有點混亂,我擔心不透明度:0;因爲SEO)。因此,如果任何人都可以用純代碼發佈一個簡單的解決方案,而沒有雜亂的東西,那就太好了:) – mdblzk
我將自己的代碼添加到了問題本身中(您可能必須等到編輯經過同行評審後才能看到)。請將代碼添加到您將來的問題中。 jsfiddle很好,但如果鏈接消失,那麼問題的價值會大大降低,因爲我們沒有代碼 –