Javascript 单击可将烤饼翻到顶部

Javascript 单击可将烤饼翻到顶部,javascript,jquery-animate,scrolltop,Javascript,Jquery Animate,Scrolltop,我尝试滚动到sticky tab navigation的顶部,该功能似乎在pageload上运行,而不仅仅是单击。我得到一个不必要的闪烁和滚动到底部的页面加载。我的代码可能有什么问题 jQuery('ul.wc-tabs li a').click(function() { var width = (window.innerWidth > 0) ? window.innerWidth : screen.width; if ( parse

我尝试滚动到sticky tab navigation的顶部,该功能似乎在pageload上运行,而不仅仅是单击。我得到一个不必要的闪烁和滚动到底部的页面加载。我的代码可能有什么问题

        jQuery('ul.wc-tabs li a').click(function() {
            var width = (window.innerWidth > 0) ? window.innerWidth : screen.width;
        if ( parseInt( width ) <= 768 ) {
            jQuery('ul.wc-tabs li').removeClass('active');
                      jQuery(this).parent('li').addClass('active');
            $("html, body").animate({scrollTop: $(".woocommerce-tabs").offset().top}, 1000);
            return;
        }
    } );
jQuery('ul.wc-tabs li a')。单击(函数(){
var width=(window.innerWidth>0)?window.innerWidth:screen.width;

如果(parseInt(width)我发现了问题。WooCommerce会自行“单击”pageload上的事件。 工作代码(第一个选项卡除外):

jQuery('ul.wc-tabs li:not(:first child)a')。单击(function(){
var width=(window.innerWidth>0)?window.innerWidth:screen.width;
if(parseInt(宽度)
         jQuery('ul.wc-tabs li:not(:first-child) a').click(function() {
                var width = (window.innerWidth > 0) ? window.innerWidth : screen.width;
        if ( parseInt( width ) <= 768 ) {
            jQuery('ul.wc-tabs li').removeClass('active');
                      jQuery(this).parent('li').addClass('active');
            $("html, body").animate({scrollTop: $(".woocommerce-tabs").offset().top}, 100);
            return;
        }
    } );