首页 > 解决方案 > viewport 不是 .js 中的函数错误

问题描述

我是 javascript 的新手,我有以下错误“未捕获的 TypeError:视口不是函数 scripts.min.js:279”,我不明白如何修复它。知道有什么问题吗?谢谢。

var lastScrollTop = 0;
    function smartSidebars() {	  //<==== line 279
    	var width = viewport().width;
    	var st = jQuery(window).scrollTop();
    	//see which direction we're going	
    	if (st > lastScrollTop){
    		var direction = 'down';
    	} else {
    		var direction = 'up';
    	}
    	affixObject(jQuery('.post-left'), jQuery('.post-right'), direction, false);	
    	if(width > 991) {
    		affixObject(jQuery('.loop-sidebar-left'), jQuery('.main-post-container'), direction, true);
    		affixObject(jQuery('.loop-sidebar-right'), jQuery('.main-post-container'), direction, true);
    		affixObject(jQuery('.single-sidebar'), jQuery('.post-right'), direction, true);
    	} else {
    		moveLoop();
    	}
    	lastScrollTop = st;		
    }


//-----------------------------------------------------------


function viewport() {
    var e = window, a = 'inner';
    if (!('innerWidth' in window )) {
        a = 'client';
        e = document.documentElement || document.body;
    }
    return { width : e[ a+'Width' ] , height : e[ a+'Height' ] };
}

标签: javascriptfunction

解决方案


推荐阅读