2017-09-07 6 views
0

要素にスクロールするときに数値にカウントされるスクリプトがありますが、何の理由もなくChrome/Firefoxで機能しなくなりました。ただし、エッジで正常に動作します。counttoスクリプトがchrome/firefoxの最新バージョンでは動作しません

キャッシュとCookieをクリアして拡張機能を無効にしようとしましたが、それでも機能しません。

$(function() { 
 
    var oTop = $('.stats').offset().top - window.innerHeight; 
 
    $(window).scroll(function() { 
 

 
    var pTop = $('body').scrollTop(); 
 
    if (pTop > oTop) { 
 
     start_count(); 
 
    } 
 
    }); 
 
}); 
 
var executed = false; // <= variable to false. 
 

 
function start_count() { 
 

 

 
    if (!executed) { // <= make sure it didn't executed before. 
 

 
    $('.stats h1').countTo({ 
 
     onComplete: function() { 
 
     var elementToPrepend = '<span style="margin-left:4px;">+</span>'; 
 
     $(elementToPrepend).hide().appendTo(this).fadeIn(); 
 

 
     } 
 
    }); 
 

 
    executed = true; // <= the count() function already executed 
 

 
    } 
 

 
}
.empty-space { 
 
    height: 500px; 
 
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-countto/1.2.0/jquery.countTo.js"></script> 
 
<div class="empty-space"> 
 
    scroll down... 
 
</div> 
 
<div class="stats"> 
 
    <h1 data-from="200" data-to="2000" data-speed="1750" data-refresh-interval="50">200</h1> 
 
</div> 
 
<div class="empty-space"> 
 
</div>

デモへのリンク:https://jsfiddle.net/30w9kbfj

クローム:バージョン61.0.3163.79(公式ビルド)(64ビット)。

Firefox:バージョン55.0.3(64ビット)。

OS: Windows 10 64ビット。

Edgeを使ってみるとうまくいかない場合は、私に教えてください。

+0

クロムで働く – anu

+0

@anuあなたのクロムのバージョンは何ですか? – ExillustX

+0

IE 11、FF、およびクロムでも動作します – CodeHacker

答えて

0

したがって、Element.scrollTopがChrome/Firefoxで更新されたという問題がありました。

Element.scrollTopdocument.scrollingElement.scrollTopを組み合わせてクロスブラウザにすることで回避策が見つかりました。

$(document.scrollingElement || "body").scrollTop(); 

Source

Document.scrollingElement

Element.scrollTop

関連する問題