简体   繁体   English

将点击事件和延迟事件添加到div(jQuery)

[英]Add click event and delay event to div (jQuery)

I want the page to slide up a div (#splash) when it loads OR at any point, the mouse can be clicked to load the slide up. 我希望页面在加载时向上滑动div(#splash), 或者在任何时候都可以单击鼠标来向上滑动幻灯片。 Heres my code which isn't working 这是我的代码不起作用

$(document).ready(function() {
    $(".fancybox").fancybox({
         openEffect : 'none',
         closeEffect    : 'none'
    });

    $("#splash").click(function(){
        $("#splash").slideUp(3000,"swing");
    });

    $("#splash").delay(2000).slideUp(3000,"swing");

});

I want it to slide up sorry. 我希望它滑起来对不起。 The splash is initially the size of the entire page. 初始大小是整个页面的大小。 I want it to slide up on load after delay, or when I click it. 我希望它在延迟后或单击时在加载时向上滑动。

Currently the div only slides up after the 2000 delay, and not when it is clicked 目前,div仅在2000延迟后才向上滑动,而不是在单击时才向上滑动

The delay function prevents the slideUp in click to execute. 延迟功能可防止单击后的slideUp执行。 Use setTimeout instead. 请改用setTimeout。


$(document).ready(function() {
    $("#splash").click(function(){
        $("#splash").slideUp(3000,"swing");
    });

    //Bad code: 
    //$("#splash").delay(5000).slideUp(3000,"swing");

    //Use setTimeOut 
    setTimeout(function (){$("#splash").slideUp(3000,"swing");} ,5000);

});

Working jsFiddle: http://jsfiddle.net/basarat/QXEVP/ 运作中的jsFiddle: http : //jsfiddle.net/basarat/QXEVP/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM