Javascript jQuery工具选项卡自定义动画
我正在我的项目中使用此库:,根据我所阅读的内容,我可以制作自定义效果,而不是使用默认效果 我决定用这样的效果:。我发现了一些类似的东西,但我在实现上遇到了困难Javascript jQuery工具选项卡自定义动画,javascript,jquery,jquery-tools,Javascript,Jquery,Jquery Tools,我正在我的项目中使用此库:,根据我所阅读的内容,我可以制作自定义效果,而不是使用默认效果 我决定用这样的效果:。我发现了一些类似的东西,但我在实现上遇到了困难 $.tools.tabs.addEffect("subFade", function(tabIndex, done) { var conf = this.getConf(), speed = conf.fadeOutSpeed, panes = this.getPanes(); var $t
$.tools.tabs.addEffect("subFade", function(tabIndex, done) {
var conf = this.getConf(),
speed = conf.fadeOutSpeed,
panes = this.getPanes();
var $tab = this.getCurrentTab();
if($tab.hasClass("current")){//Going AWAY from the tab, do hide animation (before the tab is hidden)
$(".tabs-tab").animate({"left" : "0px"}, 300, function(){//I was sliding it behind the tabs when not in use, replace with your own animation
panes.hide();
panes.eq(tabIndex).fadeIn(200, done);
console.log("Done done");
//This is then end of the chain - my animation, hide all then fade in new tab.
});
} else {//going away from any other tab
panes.hide();
panes.eq(tabIndex).fadeIn(200, done);
}
$tab = this.getTabs().eq(tabIndex);
if($tab.hasClass("current")){//Going to my special tab.
$(".tabs-tab").animate({"left" : "-160px"}, 300);//Sliding it out
}
// the supplied callback must be called after the effect has finished its job
done.call();
});
以上是我一直在尝试的,但没有成功。因此,我想知道是否有人知道我做错了什么,我如何才能使自定义效果像演示一样运行?我制作了一个与您的示例类似的内容滑块(但是它没有FadeIn/Out功能),但可能通过对我的代码进行一些修改,您就可以产生这种效果。
我的完整代码:
$(document).ready(function() {
$('.slides div:not(:first)').hide();
$('.slides div:first').addClass('active');
//Put .active width in var
var activeWidth = $(".active").outerWidth();
$('.control p:first').addClass('current');
$('.control p').click(function() {
/*store P index inside var*/
var Pindex = $(this).index();
/* Store the slides in var*/
var slidePosition=$('.wrapper .slides div');
/* check if ACTIVE slide has GREATER index than clicked P TAG (CONTROLS)*/
if($(".wrapper .slides div.active").index() > $('.wrapper .slides div').eq(Pindex).index()) {
/*Show the slide equal to clicked P-TAG(CONTROLS)*/
slidePosition.eq(Pindex).show();
/*Add class "current" to the clicked control*/
$(this).addClass('current').prevAll('.current').removeClass('current');
$(this).nextAll('.current').removeClass('current');
$(".active").removeClass("active");
$(".slides").css({"margin-left":-activeWidth});
/*Start animation...*/
$(".slides").animate({marginLeft:activeWidth-activeWidth},1000,function() {
slidePosition.eq(Pindex).addClass("active");
$(".slides").css({"margin-left":"0px"});
$(".active").prevAll().hide();
$(".active").nextAll().hide();
});
}
if($('.slides').is(':animated')) {
return false;
}
if($(this).is($(".current"))) {
return false;
}
if($(".wrapper .slides div.active").index() < $('.wrapper .slides div').eq(Pindex).index()) {
slidePosition.eq(Pindex).show();
$(this).addClass('current').prevAll('.current').removeClass('current');
$(this).nextAll('.current').removeClass('current');
$(".active").removeClass("active");
$(".slides").animate({marginLeft:-activeWidth},1000,function() {
slidePosition.eq(Pindex).addClass("active");
$(".slides").css({"margin-left":"0px"});
$(".active").prevAll().hide();
$(".active").nextAll().hide();
});
}
});
$(".left").click(function() {
if($('.slides').is(':animated')) {
return false;
}
if($(".active").prev().length===0) {
//alert("no prev");
$(".active").nextAll().clone().insertBefore(".active");
$(".active").removeClass("active").prev().addClass("active");
$(".active").show();
$(".slides").css({"margin-left":-activeWidth});
$(".slides").animate({marginLeft:activeWidth-activeWidth},1000,function() {
$(".active").next().insertBefore($(".slides div:first")).hide();
var activeIndex = $(".active").index();
$(".active").nextAll().remove();
$(".current").removeClass("current");
//alert(activeIndex)
$(".control p").eq(activeIndex).addClass("current");
});
}
else{
$(".active").removeClass("active").prev().addClass("active");
$(".active").show();
$(".slides").css({"margin-left":-activeWidth});
$(".slides").animate({marginLeft:activeWidth-activeWidth},1000,function() {
var activeIndex = $(".active").index();
$(".active").prevAll().hide();
$(".active").nextAll().hide();
$(".current").removeClass("current");
$(".control p").eq(activeIndex).addClass("current");
});
}
});
$(".right").click(function() {
if($('.slides').is(':animated')) {
return false;
}
if($(".active").next().length===0) {
//alert("no next")
$(".slides div:first").nextAll(':not(.active)').clone().insertAfter(".active");
$(".slides div:first").insertAfter(".active");
$(".active").removeClass("active").next().addClass("active");
$(".active").show();
$(".slides").animate({marginLeft:-activeWidth},1000,function() {
$(".active").prev().hide().insertAfter(".slides div:last");
$(".slides").css({"margin-left":"0px"});
$(".active").prevAll().remove();
$(".current").removeClass("current");
var activeIndex = $(".active").index();
$(".control p").eq(activeIndex).addClass("current");
});
}
else{
$(".active").removeClass("active").next().addClass("active");
$(".active").show();
$(".slides").animate({marginLeft:-activeWidth},1000,function() {
$(".slides").css({"margin-left":"0px"});
$(".active").prevAll().hide();
$(".active").nextAll().hide();
$(".current").removeClass("current");
var activeIndex = $(".active").index();
$(".control p").eq(activeIndex).addClass("current");
});
}
});
});
$(文档).ready(函数(){
$('.slides div:not(:first').hide();
$('.slides div:first').addClass('active');
//Put.activewidth在var中
var activeWidth=$(“.active”).outerWidth();
$('.control p:first').addClass('current');
$('.control p')。单击(函数(){
/*将P索引存储在var*/
var Pindex=$(this.index();
/*将幻灯片存储在var中*/
var slidePosition=$('.wrapper.slides div');
/*检查活动幻灯片的索引是否大于单击的P标记(控件)*/
if($(“.wrapper.slides div.active”).index()>$('.wrapper.slides div').eq(Pindex.index()){
/*显示与单击的P标签相同的幻灯片(控件)*/
slidePosition.eq(Pindex.show();
/*将类“current”添加到单击的控件*/
$(this).addClass('current').prevAll('.current').removeClass('current');
$(this).nextAll('.current').removeClass('current');
$(.active”).removeClass(“active”);
$(“.slides”).css({“左边距”:-activeWidth});
/*开始动画*/
$(“.slides”).animate({marginLeft:activeWidth-activeWidth},1000,function(){
slidePosition.eq(Pindex.addClass(“活动”);
$(“.slides”).css({“左边距”:“0px”});
$(“.active”).prevAll().hide();
$(“.active”).nextAll().hide();
});
}
如果($('.slides')。是(':animated'){
返回false;
}
如果($(this).is($(“.current”)){
返回false;
}
if($(“.wrapper.slides div.active”).index()<$('.wrapper.slides div').eq(Pindex.index()){
slidePosition.eq(Pindex.show();
$(this).addClass('current').prevAll('.current').removeClass('current');
$(this).nextAll('.current').removeClass('current');
$(.active”).removeClass(“active”);
$(“.slides”).animate({marginLeft:-activeWidth},1000,function(){
slidePosition.eq(Pindex.addClass(“活动”);
$(“.slides”).css({“左边距”:“0px”});
$(“.active”).prevAll().hide();
$(“.active”).nextAll().hide();
});
}
});
$(“.left”)。单击(函数(){
如果($('.slides')。是(':animated'){
返回false;
}
如果($(“.active”).prev().length==0){
//警报(“无预警”);
$(“.active”).nextAll().clone().insertBefore(“.active”);
$(.active”).removeClass(“active”).prev().addClass(“active”);
$(“.active”).show();
$(“.slides”).css({“左边距”:-activeWidth});
$(“.slides”).animate({marginLeft:activeWidth-activeWidth},1000,function(){
$(“.active”).next().insertBefore($(“.slides div:first”).hide();
var activeIndex=$(“.active”).index();
$(“.active”).nextAll().remove();
$(.current”).removeClass(“current”);
//警报(activeIndex)
$(“.control p”).eq(activeIndex).addClass(“当前”);
});
}
否则{
$(.active”).removeClass(“active”).prev().addClass(“active”);
$(“.active”).show();
$(“.slides”).css({“左边距”:-activeWidth});
$(“.slides”).animate({marginLeft:activeWidth-activeWidth},1000,function(){
var activeIndex=$(“.active”).index();
$(“.active”).prevAll().hide();
$(“.active”).nextAll().hide();
$(.current”).removeClass(“current”);
$(“.control p”).eq(activeIndex).addClass(“当前”);
});
}
});
$(“.right”)。单击(函数(){
如果($('.slides')。是(':animated'){
返回false;
}
if($(“.active”).next().length==0){
//警报(“无下一个”)
$(“.slides div:first”).nextAll(“:not(.active)”.clone().insertAfter(“.active”);
$(“.slides div:first”).insertAfter(“.active”);
$(.active”).removeClass(“active”).next().addClass(“active”);
$(“.active”).show();
$(“.slides”).animate({marginLeft:-activeWidth},1000,function(){
$(“.active”).prev().hide().insertAfter(“.slides div:last”);
$(“.slides”).css({“左边距”:“0px”});
$(“.active”).prevAll().remove();
$(.current”).removeClass(“current”);
var activeIndex=$(“.active”).index();
$(“.control p”).eq(activeIndex).addClass(“当前”);
});
}
否则{
$(.active”).removeClass(“active”).next().addClass(“active”);
$(“.active”).show();
$(“.slides”).animate({marginLeft:-activeWidth},1000,function(){
$(“.slides”).css({“左边距”:“0px”});
$(“.active”).prevAll().hide();
$(“.active”).nextAll().hide();
$(.current”).removeClass(“current”);
var activeIndex=$(“.active”).index();
$(“.control p”).eq(activeIndex).addClass(“当前”);
});
}
});
});
我制作了一个与您的示例类似的内容滑块(但是它没有FadeIn/Out功能),但可能需要对我的代码进行一些修改,您就可以实现这种效果。我的完整代码:
$(document).ready(function() {
$('.slides div:not(:first)').hide();
$('.slides div:first').addClass('active');
//Put .active width in var
var activeWidth = $(".active").outerWidth();
$('.control p:first').addClass('current');
$('.control p').click(function() {
/*store P index inside var*/
var Pindex = $(this).index();
/* Store the slides in var*/
var slidePosition=$('.wrapper .slides div');
/* check if ACTIVE slide has GREATER index than clicked P TAG (CONTROLS)*/
if($(".wrapper .slides div.active").index() > $('.wrapper .slides div').eq(Pindex).index()) {
/*Show the slide equal to clicked P-TAG(CONTROLS)*/
slidePosition.eq(Pindex).show();
/*Add class "current" to the clicked control*/
$(this).addClass('current').prevAll('.current').removeClass('current');
$(this).nextAll('.current').removeClass('current');
$(".active").removeClass("active");
$(".slides").css({"margin-left":-activeWidth});
/*Start animation...*/
$(".slides").animate({marginLeft:activeWidth-activeWidth},1000,function() {
slidePosition.eq(Pindex).addClass("active");
$(".slides").css({"margin-left":"0px"});
$(".active").prevAll().hide();
$(".active").nextAll().hide();
});
}
if($('.slides').is(':animated')) {
return false;
}
if($(this).is($(".current"))) {
return false;
}
if($(".wrapper .slides div.active").index() < $('.wrapper .slides div').eq(Pindex).index()) {
slidePosition.eq(Pindex).show();
$(this).addClass('current').prevAll('.current').removeClass('current');
$(this).nextAll('.current').removeClass('current');
$(".active").removeClass("active");
$(".slides").animate({marginLeft:-activeWidth},1000,function() {
slidePosition.eq(Pindex).addClass("active");
$(".slides").css({"margin-left":"0px"});
$(".active").prevAll().hide();
$(".active").nextAll().hide();
});
}
});
$(".left").click(function() {
if($('.slides').is(':animated')) {
return false;
}
if($(".active").prev().length===0) {
//alert("no prev");
$(".active").nextAll().clone().insertBefore(".active");
$(".active").removeClass("active").prev().addClass("active");
$(".active").show();
$(".slides").css({"margin-left":-activeWidth});
$(".slides").animate({marginLeft:activeWidth-activeWidth},1000,function() {
$(".active").next().insertBefore($(".slides div:first")).hide();
var activeIndex = $(".active").index();
$(".active").nextAll().remove();
$(".current").removeClass("current");
//alert(activeIndex)
$(".control p").eq(activeIndex).addClass("current");
});
}
else{
$(".active").removeClass("active").prev().addClass("active");
$(".active").show();
$(".slides").css({"margin-left":-activeWidth});
$(".slides").animate({marginLeft:activeWidth-activeWidth},1000,function() {
var activeIndex = $(".active").index();
$(".active").prevAll().hide();
$(".active").nextAll().hide();
$(".current").removeClass("current");
$(".control p").eq(activeIndex).addClass("current");
});
}
});
$(".right").click(function() {
if($('.slides').is(':animated')) {
return false;
}
if($(".active").next().length===0) {
//alert("no next")
$(".slides div:first").nextAll(':not(.active)').clone().insertAfter(".active");
$(".slides div:first").insertAfter(".active");
$(".active").removeClass("active").next().addClass("active");
$(".active").show();
$(".slides").animate({marginLeft:-activeWidth},1000,function() {
$(".active").prev().hide().insertAfter(".slides div:last");
$(".slides").css({"margin-left":"0px"});
$(".active").prevAll().remove();
$(".current").removeClass("current");
var activeIndex = $(".active").index();
$(".control p").eq(activeIndex).addClass("current");
});
}
else{
$(".active").removeClass("active").next().addClass("active");
$(".active").show();
$(".slides").animate({marginLeft:-activeWidth},1000,function() {
$(".slides").css({"margin-left":"0px"});
$(".active").prevAll().hide();
$(".active").nextAll().hide();
$(".current").removeClass("current");
var activeIndex = $(".active").index();
$(".control p").eq(activeIndex).addClass("current");
});
}
});
});
$(文档).ready(函数(){
$('.slides div:not(:first').hide();
$('.slides div:first').addClass('active');
//Put.activewidth在var中
var activeWidth=$(“.active”).outerWidth();
$('.control p:first').addClass('current');
$('.control p')。单击(函数(){
/*将P索引存储在var*/
var Pindex=$(this.index();
/*将幻灯片存储在var中*/
var slidePosition=$('.wrapper.slides div');
/*检查活动幻灯片的索引是否大于单击的P标记(控件)*/
if($(“.wrapper.slides div.active”).index()>$('.wrapper.slides div').eq(Pindex.index()){
/*放映幻灯片