簡體   English   中英

當頁面動畫到頂部以獲得目標位置時,如何在單擊..時獲得窗口滾動單位

[英]How to get window scroll unit on click .. when a page is animating to top for target position

我需要在窗口滾動和導航單擊上進行視差滾動。在導航單擊頁面中,動畫在頂部以顯示目標。

當頁面動畫到目標位置的頂部時,如何獲得單擊時的窗口滾動單位。

/ *使用此代碼,我試圖獲取窗口滾動單元* /

$glob(document).ready(function() {
                $glob("#lookbook_navi a").bind("click",function(event){
                    event.preventDefault();
                    var target = $glob(this).attr("href");

                    var objWindow = $glob(window);

                    $window = $glob(window);
                    alert($window.scrollTop()); 

                    $glob("#page").animate({
                        "top": -($glob(target).position().top)
                    }, animSpeed);



                });
            });

/ 通過此代碼,我獲得了窗口滾動的單位。

$glob(document).ready(function(){
                // Cache the Window object
                $window = $glob(window);

               $glob('div[data-type="lookBookTab"]').each(function(){
                    var $bgobj = $glob(this); // assigning the object

                    $glob(window).scroll(function() {

                        // Scroll the background at var speed
                        // the yPos is a negative value because we're scrolling it UP!                              
                        var yPos = -($window.scrollTop() / $bgobj.data('speed')); 

                        // Put together our final background position
                        var coords = '50% '+ yPos + 'px';

                        // Move the background
                        $bgobj.css({ backgroundPosition: coords });

                    }); // window scroll Ends
                }); 

試試這個

$('a[href^="#"]').on('click',function (e) {
        e.preventDefault();
        var target = this.hash,
        $target = $(target);
        $('html, body').stop().animate({
            'scrollTop': $target.offset().top
        }, 500, 'swing', function () {
            window.location.hash = target;
        });
    });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM