我正在将一些 jQuery 变成一个插件,但我想出了错误。这是正常的 jQuery 代码。
var current = ($("#gallery a.show")? $("#gallery a.show") : $("#gallery a:first"));
这是jQuery插件代码
var current = ($(this).find("a.show")? $(this).find("a.show") : $(this).find("a:first"));
帮助将不胜感激。
这是所有jQuery 插件代码。
$(window).load(function(){
$("#gallery").csstubeslider();
});
$.fn.csstubeslider = function(){
$(this).animate({'opacity': '1'}, 500);
$(this).find(".caption").css("opacity", 0.7);
$(this).find("a").css("opacity", "0");
$(this).find("a.show").css("opacity", "1");
var hasplayed = false;
if(hasplayed == false){
setTimeout(function hello(){
$(this).find(".caption").animate({"height": 0, "opacity": 0}, 500);
hasplayed == true;
}, 4500);
}
setInterval(function(){
var current = ($(this).find("a.show")? $(this).find("a.show") : $(this).find("a:first"));
var next = ((current.next())? (current.next().hasClass("caption"))? $(this).find("a:first") : current.next() : $(this).find("a:first"));
var content = next.find("img").attr("rel");
next.addClass("show").animate({"opacity": "1.0"}, 500);
current.removeClass('show').animate({"opacity": "0"}, 500);
setTimeout(function(){
$(this).find(".caption").animate({"height": 0, "opacity": 0}, 500);
}, 4500);
$(this).find(".content").html(content);
}, 1000);
}
这是jQuery代码。
$(window).load(function(){
$("#gallery").animate({'opacity': '100'}, 5000);
$("#gallery .caption").css("opacity", 0.8);
slideshow();
});
function slideshow(){
$("#gallery a").css("opacity", "0");
$("#gallery a.show").css("opacity", "1");
var content = $("#gallery a.show").find("img").attr("rel");
$("#gallery .content").html(content);
var hasplayed = false;
if(hasplayed == false){
setTimeout(function hello(){
$("#gallery .caption").animate({"height": 0, "opacity": 0}, 500);
hasplayed == true;
}, 4500);
}
setInterval("playimages()", 5500);
}
function playimages(){
var current = ($("#gallery a.show")? $("#gallery a.show") : $("#gallery a:first"));
var next = ((current.next())? (current.next().hasClass("caption"))? $("#gallery a:first") : current.next() : $("#gallery a:first"));
var content = next.find("img").attr("rel");
next.addClass("show").animate({"opacity": "1.0"}, 500);
current.removeClass('show').animate({"opacity": "0"}, 2000);
$("#gallery .caption").css("height", 0).animate({"height": 60, "opacity": 0.8}, 500);
setTimeout(function hello(){
$("#gallery .caption").animate({"height": 0, "opacity": 0}, 500);
}, 4500);
$("#gallery .content").html(content);
}