首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >跳过JQuery中的动画函数

问跳过JQuery中的动画函数
EN

Stack Overflow用户
提问于 2012-11-28 21:57:00
回答 2查看 772关注 0票数 0

我有一个功能,动画的小介绍,但我想把一个跳过按钮在那里,以便它将加载页面直接没有介绍,如果人不想看这个简短的介绍。但是,当我尝试这样做时,它似乎不起作用?以下是Javascript代码:

代码语言:javascript
复制
$(document).ready(function() {
$(window).bind("unload", function() {
});

imageresize();  
aboutdisplay();
pageload();
intro();
start();


jQuery.easing.def = "easeOutElastic";

$("#bg a").click(function(event){
    event.preventDefault();
});

var $backgrounds = $('#bg li img');
var $menu_items = $('#menu li a');

$menu_items.hover(function(event){
    event.preventDefault();
    var $bg = $backgrounds.eq($menu_items.index(this));
    $bg.stop(true, false).animate({opacity:"1"},500, 'linear');},
        function() {
    var $bg = $backgrounds.eq($menu_items.index(this));
    $bg.stop(true, false).delay(250).animate({opacity:"0"},750, 'linear');
});

    $("a.skip").click(function(event){
    event.preventDefault();
    skip();
}); 

$("a.close2").click(function(event){
    event.preventDefault();
    $("#about").animate({'top':"-1500px"},500, 'linear');
    $("#modelling").animate({'top':"-1000px"},500, 'linear');
    $("#photography").animate({'top':"-1000px"},500, 'linear');
    $("#graphics").animate({'top':"-1000px"},500, 'linear');
    $("#webdesign").animate({'top':"-1000px"},500, 'linear');
    $("#video").animate({'top':"-1000px"},500, 'linear');
    $("#contact").animate({'top':"-1000px"},500, 'linear');
    $("#fade").animate({opacity:"0"},500, 'linear');
    $("#menu").animate({opacity:"1", 'top':"50%"}, 1000);
    $("#menu2").animate({'left':"-1500px"},500);
    $("#border2").animate({'height':"50px"},500, 'linear');
});




$("a.transition2").click(function(event){
    event.preventDefault();
    $("#menu2").animate({'left':"-20px"},2000);
    $("#about").delay(500).animate({'opacity':"1",'top':"10px"},1000);
    $("#fade").animate({opacity:"0.9"},500, 'linear');
    $("#menu").animate({opacity:"0", 'top':"-100%"}, 500, 'linear');
    $("#border2").animate({'height':"75px"},1000, 'linear');
});
$("a.transition2_1").click(function(event){
    event.preventDefault();
    $("#about").delay(500).animate({'opacity':"1",'top':"10px"},1000);
    $("#modelling").animate({'top':"-1000px"},500, 'linear');
    $("#photography").animate({'top':"-1000px"},500, 'linear');
    $("#graphics").animate({'top':"-1000px"},500, 'linear');
    $("#webdesign").animate({'top':"-1000px"},500, 'linear');
    $("#video").animate({'top':"-1000px"},500, 'linear');
    $("#contact").animate({'top':"-1000px"},500, 'linear');
    $("#fade").animate({opacity:"0.9"},500, 'linear');
    $("#menu").animate({opacity:"0", 'top':"-100%"}, 500, 'linear');
});


$("a.transition3").click(function(event){
    event.preventDefault();
    $("#menu2").animate({'left':"-20px"},2000);
    $("#modelling").delay(500).animate({'opacity':"1",'top':"10px"},1000);
    $("#fade").animate({opacity:"0.9"},500, 'linear');
    $("#menu").animate({opacity:"0", 'top':"-100%"}, 500, 'linear');
    $("#border2").animate({'height':"75px"},1000, 'linear');
});
$("a.transition3_1").click(function(event){
    event.preventDefault();
    $("#modelling").delay(500).animate({'opacity':"1",'top':"10px"},1000);
    $("#about").animate({'top':"-1500px"},500, 'linear');
    $("#photography").animate({'top':"-1000px"},500, 'linear');
    $("#graphics").animate({'top':"-1000px"},500, 'linear');
    $("#webdesign").animate({'top':"-1000px"},500, 'linear');
    $("#video").animate({'top':"-1000px"},500, 'linear');
    $("#contact").animate({'top':"-1000px"},500, 'linear');
    $("#fade").animate({opacity:"0.9"},500, 'linear');
    $("#menu").animate({opacity:"0", 'top':"-100%"}, 500, 'linear');
});


$("a.transition4").click(function(event){
    event.preventDefault();
    $("#menu2").animate({'left':"-20px"},2000);
    $("#photography").delay(500).animate({'opacity':"1",'top':"10px"},1000);
    $("#fade").animate({opacity:"0.9"},500, 'linear');
    $("#menu").animate({opacity:"0", 'top':"-100%"}, 500, 'linear');
    $("#border2").animate({'height':"75px"},1000, 'linear');
});
$("a.transition4_1").click(function(event){
    event.preventDefault();
    $("#photography").delay(500).animate({'opacity':"1",'top':"10px"},1000);
    $("#modelling").animate({'top':"-1000px"},500, 'linear');
    $("#about").animate({'top':"-1500px"},500, 'linear');
    $("#graphics").animate({'top':"-1000px"},500, 'linear');
    $("#webdesign").animate({'top':"-1000px"},500, 'linear');
    $("#video").animate({'top':"-1000px"},500, 'linear');
    $("#contact").animate({'top':"-1000px"},500, 'linear');
    $("#fade").animate({opacity:"0.9"},500, 'linear');
    $("#menu").animate({opacity:"0", 'top':"-100%"}, 500, 'linear');
});


$("a.transition5").click(function(event){
    event.preventDefault();
    $("#menu2").animate({'left':"-20px"},2000);
    $("#video").delay(500).animate({'opacity':"1",'top':"10px"},1000);
    $("#fade").animate({opacity:"0.9"},500, 'linear');
    $("#menu").animate({opacity:"0", 'top':"-100%"}, 500, 'linear');
    $("#border2").animate({'height':"75px"},1000, 'linear');
});
$("a.transition5_1").click(function(event){
    event.preventDefault();
    $("#video").delay(500).animate({'opacity':"1",'top':"10px"},1000);
    $("#modelling").animate({'top':"-1000px"},500, 'linear');
    $("#about").animate({'top':"-1500px"},500, 'linear');
    $("#photography").animate({'top':"-1000px"},500, 'linear');
    $("#webdesign").animate({'top':"-1000px"},500, 'linear');
    $("#graphics").animate({'top':"-1000px"},500, 'linear');
    $("#contact").animate({'top':"-1000px"},500, 'linear');
    $("#fade").animate({opacity:"0.9"},500, 'linear');
    $("#menu").animate({opacity:"0", 'top':"-100%"}, 500, 'linear');
});


$("a.transition6").click(function(event){
    event.preventDefault();
    $("#menu2").animate({'left':"-20px"},2000);
    $("#graphics").delay(500).animate({'opacity':"1",'top':"10px"},1000);
    $("#fade").animate({opacity:"0.9"},500, 'linear');
    $("#menu").animate({opacity:"0", 'top':"-100%"}, 500, 'linear');
    $("#border2").animate({'height':"75px"},1000, 'linear');
});
$("a.transition6_1").click(function(event){
    event.preventDefault();
    $("#graphics").delay(500).animate({'opacity':"1",'top':"10px"},1000);
    $("#modelling").animate({'top':"-1000px"},500, 'linear');
    $("#about").animate({'top':"-1500px"},500, 'linear');
    $("#webdesign").animate({'top':"-1000px"},500, 'linear');
    $("#photography").animate({'top':"-1000px"},500, 'linear');
    $("#video").animate({'top':"-1000px"},500, 'linear');
    $("#contact").animate({'top':"-1000px"},500, 'linear');
    $("#fade").animate({opacity:"0.9"},500, 'linear');
    $("#menu").animate({opacity:"0", 'top':"-100%"}, 500, 'linear');
});


$("a.transition7").click(function(event){
    event.preventDefault();
    $("#menu2").animate({'left':"-20px"},2000);
    $("#webdesign").delay(500).animate({'opacity':"1",'top':"10px"},1000);
    $("#fade").animate({opacity:"0.9"},500, 'linear');
    $("#menu").animate({opacity:"0", 'top':"-100%"}, 500, 'linear');
    $("#border2").animate({'height':"75px"},1000, 'linear');
});
$("a.transition7_1").click(function(event){
    event.preventDefault();
    $("#webdesign").delay(500).animate({'opacity':"1",'top':"10px"},1000);
    $("#modelling").animate({'top':"-1000px"},500, 'linear');
    $("#about").animate({'top':"-1500px"},500, 'linear');
    $("#graphics").animate({'top':"-1000px"},500, 'linear');
    $("#video").animate({'top':"-1000px"},500, 'linear');
    $("#photography").animate({'top':"-1000px"},500, 'linear');
    $("#contact").animate({'top':"-1000px"},500, 'linear');
    $("#fade").animate({opacity:"0.9"},500, 'linear');
    $("#menu").animate({opacity:"0", 'top':"-100%"}, 500, 'linear');
});


$("a.transition8").click(function(event){
    event.preventDefault();
    $("#menu2").animate({'left':"-20px"},2000);
    $("#contact").delay(500).animate({'opacity':"1",'top':"10px"},1000);
    $("#fade").animate({opacity:"0.9"},500, 'linear');
    $("#menu").animate({opacity:"0", 'top':"-100%"}, 500, 'linear');
    $("#border2").animate({'height':"75px"},1000, 'linear');
});
$("a.transition8_1").click(function(event){
    event.preventDefault();
    $("#contact").delay(500).animate({'opacity':"1",'top':"10px"},1000);
    $("#modelling").animate({'top':"-1000px"},500, 'linear');
    $("#about").animate({'top':"-1500px"},500, 'linear');
    $("#graphics").animate({'top':"-1000px"},500, 'linear');
    $("#webdesign").animate({'top':"-1000px"},500, 'linear');
    $("#video").animate({'top':"-1000px"},500, 'linear');
    $("#photography").animate({'top':"-1000px"},500, 'linear');
    $("#fade").animate({opacity:"0.9"},500, 'linear');
    $("#menu").animate({opacity:"0", 'top':"-100%"}, 500, 'linear');
});
   });

function imageresize() {  
    var bodywidth = $('#photography').width();  
    if ((bodywidth) < '1450'){  
        $('#photophotos img').css({'width':'150px', 'height':'112px'});
        $('#videophotos img').css({'width':'150px', 'height':'112px'});
        $('#graphicsphotos img').css({'width':'150px', 'height':'112px'});
        $('#webphotos img').css({'width':'250px', 'height':'187px'});
        $('#modelphotos img').css({'width':'150px', 'height':'112px'});
        $('#menu2').css({'font-size':'0.8em'});
        $('#aboutbio').css({'width':'560px','font-size':'1em'});    
        $('#aboutphotos img').css({'width':'200px', 'height':'150px'});
    } else {  
        $('#photophotos img').css({'width':'250px', 'height':'187px'});
        $('#videophotos img').css({'width':'250px', 'height':'187px'});  
        $('#graphicsphotos img').css({'width':'250px', 'height':'187px'});  
        $('#webphotos img').css({'width':'325px', 'height':'243px'});  
        $('#modelphotos img').css({'width':'250px', 'height':'187px'});
        $('#menu2').css({'font-size':'1.3em'});
        $('#aboutbio').css({'width':'700px', 'font-size':'1.2em'});
        $('#aboutphotos img').css({'width':'250px', 'height':'187px'});                 
    }  
}  

$(window).bind("resize", function(){//Adjusts image when browser resized  
    imageresize();  
});  

function aboutdisplay() {  
    var bodywidth = $('#photography').width();  
    if ((bodywidth) < '1050'){  
        $('#aboutphotos').css({'display':'none'});
    } else { 
        $('#aboutphotos').css({'display':'block'});
    }  
}  

$(window).bind("resize", function(){//Adjusts image when browser resized  
    aboutdisplay();  
});

function pageload(){
    $('#bg').hide();
    $('#border').hide();
    $('#menu').hide();
    $('#words p').hide();
    $('#social').hide();
    $('#border2').hide();
}

function intro(){
    $('#words2 ul').animate({'margin-top':'300px'}, 500, 'linear').delay(200).animate({'margin-top':'250px'}, 500, 'linear').delay(200)
        .animate({'margin-top':'200px'}, 500, 'linear').delay(200).animate({'margin-top':'150px'}, 500, 'linear').delay(200)
        .animate({'margin-top':'100px'}, 500, 'linear').delay(200).animate({'margin-top':'50px'}, 500, 'linear').delay(200)
        .animate({'margin-top':'0px'}, 500, 'linear');
}

function start(){
    $('#words2').delay(7500).fadeOut(500, 'linear');
    $('#bg').delay(6500).fadeIn(1000, 'linear');
    $('#border').delay(7500).fadeIn(1000, 'linear');
    $('#border2').delay(7500).fadeIn(1000, 'linear');
    $('#menu').delay(8000).fadeIn(1000, 'linear');
    $('#words p').delay(8000).fadeIn(1000, 'linear');
    $('#social').delay(9000).fadeIn(1000, 'linear');
}

function skip(){
    $('#words2').fadeOut(500, 'linear');
    $('#bg').fadeIn(1000, 'linear');
    $('#border').fadeIn(1000, 'linear');
    $('#border2').fadeIn(1000, 'linear');
    $('#menu').fadeIn(1000, 'linear');
    $('#words p').fadeIn(1000, 'linear');
    $('#social').fadeIn(1000, 'linear');
}

有没有人能看到我哪里出了问题?

干杯

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-11-28 22:10:02

如果只是尝试跳过动画,则应该在clearQueue参数设置为true的情况下使用.stop()。

代码语言:javascript
复制
function skip(){
    $('#words2').stop(true).fadeOut(500, 'linear');
    $('#bg').stop(true).fadeIn(1000, 'linear');
    $('#border').stop(true).fadeIn(1000, 'linear');
    $('#border2').stop(true).fadeIn(1000, 'linear');
    $('#menu').stop(true).fadeIn(1000, 'linear');
    $('#words p').stop(true).fadeIn(1000, 'linear');
    $('#social').stop(true).fadeIn(1000, 'linear');
}

您不能使用jQuery跳过对delay()的调用。如果你需要更多的控制,我建议使用原生JavaScript超时。

票数 0
EN

Stack Overflow用户

发布于 2012-11-28 22:07:23

您需要先停止其他动画。

如果没有小提琴或其他演示要看,我最好的猜测是,你试图在没有首先停止已经开始的动画/效果的情况下淡入页面内容。您不能简单地调用冲突的动画/效果,而不先取消前一个动画/效果。

要停止正在运行的动画/效果,您需要使用jQuery的.stop()方法。

如果你有任何问题,请告诉我。祝你好运!:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13606775

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档