我试图传递一个类和id作为参数,在函数内部使用,我做了一些错误,但我不知道是什么。
代码:http://jsfiddle.net/XTF4e/
$(window).load(function () {
bubbles({
bubble: '#bubble',
quotes: '.quote'
})
});
function bubbles(bubble) {
function show(bubble) {
$(bubble.bubble).delay(200).fadeIn(1000);
}
function hide(bubble) {
setTimeout(function () {
if ($(bubble.bubble).length > 0) {
$(bubble.bubble).fadeOut(1000);
}
}, 5000)
}
function addtext(bubble) {
var quotes = new Array("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", "bar", "baz", "chuck");
var randno = Math.floor(Math.random() * (quotes.length));
$(bubble.quotes).append(quotes[randno]);
console.log(randno);
$(bubble.bubble).click(function () {
$(bubble.bubble).fadeOut(1000);
});
}
}发布于 2014-05-20 09:54:37
在函数bubbles的底部,您忘记调用这三个函数,就在上一个}之前。
show( bubble );
hide( bubble );
addtext( bubble );函数是定义的,但必须调用它们才能触发它们。
https://stackoverflow.com/questions/23756266
复制相似问题