我是一个更新,更新的测试,滚动时我的页面出现控制台错误,它说像
main.js:18
未捕获的TypeError:无法读取属性' top'未定义的
at main.js:18
at dispatch (jquery-1.9.js:3)
at v.handle (jquery-1.9.js:3)
我尝试了其他解决方案,例如将选择器更改为变量,但错误没有解决,我想我想搜索整个页面进行更正,但我没有确定这里是我的页面main.js
/**
Visionmax v 1.0
Available on ThemeForest - http://themeforest.net/user/nasirwd/portfolio
Author: NasirWd - http://www.nasfactor.com
**/
/*global $:false */
(function(){
"use strict";
$(window).load(function(){
$("#nav-sticky").sticky({ topSpacing: 0 });
});
/* home page soild features animation*/
$(window).scroll(function(){ // scroll event
var windowTop = $(window).scrollTop(); // returns number
var nav=$('.solid-visuals');
var solid_action = nav.offset().top-500;
if (windowTop >= solid_action)
{
$('.solid-iphone,.solid-imac').addClass('animated fadeInUp');
}
});
/*smooth scrolling*/
$(document).ready(function() {
// $("html").niceScroll(); // The document page (html)
$("body").niceScroll({touchbehavior:false,cursorcolor:"#000",cursoropacitymax:1,cursorwidth:8,background:"#333",autohidemode:true});
});
$(function(){var nice=$(":nicescroll").getNiceScroll(0);$("#div1").html($("#div1").html()+' '+nice.version+' ($:'+$().jquery+')')})
/*home page showcase javascript*/
$(function(){
$(window).on("resize", function () {
var etwrapper_height= $('.show-case-visual img').height();
$('.et-wrapper').height(etwrapper_height);
var etwrapper_basic_height= $('.folio-visual').height();
$('.et-wrapper-basic').height(etwrapper_basic_height+100);
var showcase_hover= $('.show-case-visual img').width();
$('.show-case-visual').width(showcase_hover);
$('.showcase-hover').width(showcase_hover-5);
var $container = $('.masonry-container');
$container.masonry({
itemSelector: '.post-unit'
});
}).resize();
/*flicker plugin*/
$('.flicker').jflickrfeed({
limit: 6,
qstrings: {
/*add your id below*/
id: '52617155@N08'
},
itemTemplate: '<li><a href="{{image_b}}"><img alt="{{title}}" src="{{image_s}}" /></a></li>'
});
/*twitter plugin*/
$('#tweets').tweetable({
/*add your username below*/
username: 'envato',
time: true,
rotate: true,
speed: 4000,
limit: 4,
replies: false,
position: 'append',
loading: 'loading...' ,
failed: "Sorry, twitter is currently unavailable for this user.",
html5: true
});
/*testimonial slider*/
$('.testi-inner').flexslider({
animation: "slide",
directionNav: false,
controlNav: true,
pauseOnHover: true,
slideshow: false,
direction: "horizontal", //Direction of slides
});
/*Flex blog slider*/
$('.blog-slider').flexslider({
animation: "slide",
controlNav: false,
});
/*Flex slider*/
$('.flexslider').flexslider({
animation: "slide"
});
/* Light Box*/
$(document).ready(function() {
$('.image-link').magnificPopup({type:'image'});
});
/*footer icons*/
$('.head-icon').hover(function(){
$(this).addClass('animated tada');
},function(){
$(this).removeClass('animated tada');
});
});
})();
请帮我解决我的错误...
答案 0 :(得分:0)
在使用top之前检查元素是否存在。
var nav = $('.solid-visuals');
if (nav.length) {
var solid_action = nav.offset().top-500;
}