2012-02-09 21 views
1

scrollTop jqueryアニメーションに問題があります。 アニメーションの直前でマイクロジャンプします。内容が重いほど、最悪です。scrollTop jqueryアニメーションを使用したときのMircoジャンプ

は、私はそれはそれをするのか理由を理解していない...以下

、私のコードのサンプルを。 (単にファイルをコピー/ペーストし、それはスタンドアロンのコードですが、私はjsfiddleには良い結果を持っていない)

<html> 
<head> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
</head> 
<body> 
<style> 
html,body{height:100%;width:100%}body{width:100%;height:100%}section{display:block;width:896px;margin:0 auto;padding:0 48px}article{content:' ';position:relative;display:block;top:0;width:100%;height:500px;padding:20% 0}#ghostPage{height:30px;padding:0}section div{text-align:center;width:100%;height:100%}#page1 div{background-color:red}#page2 div{background-color:blue}#page3 div{background-color:#A52A2A}#page4 div{background-color:green}#page5 div{background-color:#FF0}#page6 div{background-color:#000}#page7 div{background-color:orange}#page8 div{background-color:purple}#page_loader{text-align:center;position:fixed;top:0;left:0;background-color:white;width:100%;height:100%;z-index:9999} 
</style> 
<section class="clearfix"> 
    <div id="page_loader" class="loader1"></div> 
    <article id="page1"> 
     <div>Page1</div> 
    </article> 
    <article id="page2"> 
     <div>Page2</div> 
    </article> 
    <article id="page3"> 
     <div>Page3</div> 
    </article> 
    <article id="page4"> 
     <div>Page4</div> 
    </article> 
    <article id="page5"> 
     <div>Page5</div> 
    </article> 
    <article id="page6"> 
     <div style="color: white">Page6</div> 
    </article> 
    <article id="page7"> 
     <div>Page7</div> 
    </article> 
    <article id="page8"> 
     <div>Page8</div> 
    </article> 
    <article id="ghostPage"></article> 
</section> 
</body> 
<script type="text/javascript"> 
/* 
** 
** Sliding 
** 
*/ 
function goToByScroll(id) { 
    var speed = 1200; 

    var offset = $('#page'+id).offset(); 
    if (offset) { 
     $('body').stop().animate({scrollTop: offset.top},{duration: speed, queue: false}); 
     window.location = '#page'+id; 
    } 
} 

/* 
** 
** Get current page id 
** 
*/ 
function getPageId() { 
    var url = document.location.toString(); 
    if (url.match('#')) { 
     var anchor = url.split('#')[1]; 
     var anchorId = parseInt(anchor.split('page')[1]); 
     if (!isNaN(anchorId)) 
      return anchorId; 
    } 
    return 1; 
} 

/* 
** 
** MouseWheel handling 
** 
*/ 
function handle(delta) { 
    if (delta > 0) 
     goToByScroll(getPageId() - 1); 
    else if (delta < 0) 
     goToByScroll(getPageId() + 1); 
} 

function wheel(event){ 
    event.preventDefault(); 
    event.stopPropagation(); 

    var delta = 0; 
    if (event.wheelDelta) 
     delta = event.wheelDelta/120; 
    else if (event.detail) 
     delta = -event.detail/3; 

    if (delta) 
     handle(delta); 
} 
if (window.addEventListener) 
    window.addEventListener('DOMMouseScroll', wheel, false); 
window.onmousewheel = document.onmousewheel = wheel; 

/*fades le loader mask out*/ 
$(document).ready(function() { 
    $('#page_loader').css('background-image', 'none'); 
    $('#page_loader').css('background-color', 'rgba(255, 255, 255, 0)').animate('slow', function(){$('#page_loader').css('z-index', '-9999');}); 
}); 
</script> 
</html> 

コンテンツは、重いではありませんので、それはバグを参照するのは難しいです。 Firefoxでは、見やすくなり、素早くスクロールすることができます。

私はあなたの良いアドバイスを待っています。 :)

+0

追加情報を提供してくださいあなたは試しましたか?それらのすべてで起こるのでしょうか? –

+0

ChromeとFirefoxでWindows 7でテスト済みです。 (最後のバージョンでも) 私はipad 1と2でそれをテストしました。(同じバグ...) 投稿時に軽量のコンテンツでスクロールすると速く点滅します。そして、Chromeは最適化のために見ていなければなりません。 ^^ – rmNyro

+0

私はjsFiddleにコードをコピーしました:http://jsfiddle.net/h6CS4/1/ - ちょっと面白いですね^^ –

答えて

1

OKこの問題は、この行です。window.location = '#page' + id; ハッシュタグを変更することで、ページが指定された要素にジャンプし、jQueryが起動して同じIDにアニメーション化されます。私は少し周りをしようとした私の最終バージョンはこれです:http://jsfiddle.net/h6CS4/6/ それは素晴らしいではありませんけれども...

は、このプラグインを試す代わりにホイールを再発明する:どのオペレーティングシステム/ブラウザ:http://flesler.blogspot.com/2007/10/jqueryscrollto.html

+0

あなたは正しいと思いますが、私はばかです...たくさんありがとう!私は最終的にスクロール後に更新する(汚い)グローバル変数を使用しました。 私は可能なときにホイールを再発明することを好む。 (私はあまりにも多くの重いプラグインを使用する必要があります) – rmNyro

関連する問題