目前正在研究新闻滚动器 - 请参阅我的现场示例 -EXAMPLE http://jsfiddle.net/MrTest/dwMfv/5/
当我按下一个/上一个箭头时,我收到错误日志Uncaught Syntax error, unrecognized expression: [object Object]
为什么会出现问题呢?语法错误在哪里?
jQuery 代码:
(function($) {
/*! Scroller
---------------------------------------------*/
$.fn.Scroller = function() {
//Set height
$('.scroller').each(function() {
var height = 0;
$(this).children('div').each(function() {
if (height < $(this).height()) {
height = $(this).height();
}
});
$(this).css("height", height + "px");
});
$('.scroller').each(function() {
var NextArrow = $(this).parent().find('.next');
var PrevArrow = $(this).parent().find('.prev');
// Set a timeout
var timeOut = setTimeout(nextNotice, 5000);
// pause on hover
$(this).hover(
function() {
clearTimeout(timeOut);
}, function() {
timeOut = setTimeout(nextNotice, 5000);
});
// Next notice function called on timeout or click
//set a flag that use to be an oberver to listen when the fadeIn done
var flag = true;
function nextNotice(event) {
var CurrentScrollerDiv = $(this).parent().find('.scroller');
if (!flag) {
return false;
}
clearTimeout(timeOut);
flag = false;
timeOut = setTimeout(nextNotice, 5000);
if ($(CurrentScrollerDiv + ' div:visible').is(CurrentScrollerDiv + ' div:last-child')) {
$(CurrentScrollerDiv + ' div:visible').fadeOut(300);
$(CurrentScrollerDiv + ' div:first-child').fadeIn("slow", function() {
flag = true;
});
} else {
$(CurrentScrollerDiv + ' div:visible').fadeOut(300).next('div').fadeIn("slow", function() {
flag = true;
});
}
return false;
}
$(NextArrow).click(nextNotice);
$(PrevArrow).click(function(event) {
var CurrentScrollerDiv = $(this).parent().find('.scroller');
if (flag) {
return false;
}
clearTimeout(timeOut);
flag = false;
timeOut = setTimeout(nextNotice, 5000);
if ($(CurrentScrollerDiv + ' div:visible').is(CurrentScrollerDiv + ' div:first-child')) {
$(CurrentScrollerDiv + ' div:visible').fadeOut(300);
$(CurrentScrollerDiv + ' div:last-child').fadeIn("slow", function() {
flag = true;
});
}
else {
$(CurrentScrollerDiv + ' div:visible').fadeOut(300).prev('div').fadeIn("slow", function() {
flag = true;
});
}
return false;
});
});
};
})(jQuery);
$(document).ready(function() {
//Blog
$('.itBlog > div:first-child').show();
//Scroller
$('.scroller').Scroller();
});
要从现有对象构建选择器,请使用第二个参数$ http://api.jquery.com/jQuery/:
$('div:visible', CurrentScrollerDiv)
Or the find功能 http://api.jquery.com/find/:
CurrentScrollerDiv.find('div:visible');
CurrentScrollerDiv
不是字符串,因此它不能与字符串连接来生成基于字符串的选择器参数。
jQuery( selector, [ context ] )
jQuery( selector, [context] ) <-- you want this one, and
jQuery( element ) `selector` is a string
jQuery( elementArray )
jQuery( jQuery object )
jQuery()
jQuery( html, [ ownerDocument ] )
jQuery( html, [ownerDocument] )
jQuery( html,props )
jQuery( callback )
jQuery( callback )
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)