简体   繁体   中英

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

I need to do parallax scrolling on window scroll and also on navigation click.. In navigation click page is animating on top to show target.

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

/*with this code i am trying to get window scroll unit */

$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);



                });
            });

/ With this code i am getting unit of window scrolling.. /

$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
                }); 

Try this one

$('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;
        });
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM