dpz1983 2015-12-31 03:20
浏览 11

滚动变得生涩

I have some code that lets me scroll up the page. The problem is that one of my classes creates the upward scroll, but then when i manually try to scroll down the page, it scrolls back up a few times! Is it common? How do i fix this?

a snippet from my php code

$links .= '<a href="#!" class="sidenav-link" default-rel="'.$default_rel.'" rel="'.$rel.'"><i class="fa fa-'.$new_v['icon'].'"></i> '.$new_v['subheader_name'].'</a>';

And here is my jquery function that gets content from a page

function toggleContent(selector, event)
{   
    var queryString = createQueryString(selector);

    $.ajax({ 
        url: 'ajaxLoad.php?'+queryString,
        method: 'GET',
        success: function(response) {

            $("#page-wrapper .container-fluid").html(response.html);
            eval($(response.js).text());

            //optional msg
            var information = $(selector).attr("information");
            var danger = $(selector).attr("danger");
            if (!information == "")
            {
                displayInformation(information);
            }
            if (!danger == "")
            {
                displayDanger(danger);
            }
            //reset msg
            $(selector).attr("information","");
            $(selector).attr("danger","");

            // run specific code
            if (typeof runSpecific == 'function') 
            { 
                runSpecific(selector, event); 
            }

            // scroll up 
            $(".btn, .list-group-item, .sidenav-link").on("click",function(){
                $("html, body").animate({ scrollTop: 0}, 300);                                              
            }); 
        }
    });

    // reset rel
    $(selector).attr('rel', $(selector).attr('default-rel') );
}

Note that .btn and .list-group-item do not create this issue, only the .sidenav-link.

  • 写回答

1条回答 默认 最新

  • dongliqian6245 2015-12-31 04:44
    关注

    Okay, perfect, I found a solution that works perfectly. All i had to do is add the stop() function before the animate() function!

    评论

报告相同问题?