简体   繁体   English

仅当元素未与之交互时,才如何为其设置动画?

[英]How do I animate an element only if it has not been interacted with?

I want to create a popout that is visible when the page loads but if the user does not interact with it, it will slide off screen after a set amount of time. 我想创建一个弹出页面,当页面加载时可见,但是如果用户不与之交互,则它将在设置的时间后滑出屏幕。

This would be using jQuery and I have found an example but been unable to recreate it. 这将使用jQuery,但我找到了一个示例,但无法重新创建它。

Here is the example site: http://www.greatwolf.com/ 这是示例网站: http : //www.greatwolf.com/

You can see their "Book Your Stay" popout will close after a few seconds if it has not been interacted with. 如果未与他们互动,您会看到他们的“预订您的住宿”弹出窗口将在几秒钟后关闭。 but if you select a date within the popout it will not close. 但是如果您在弹出窗口中选择一个日期,它将不会关闭。

I know how to make something animate after a delayed time of course. 我当然知道在延迟的时间后如何制作动画。

 $('.side-res-widget-trigger').delay(3000).animate({
        left: parseInt($('.side-res-widget-trigger').css('left'),10) == 0 ?
            -$('.side-res-widget-trigger').outerWidth() :
            0
    });
    $('.side-res-widget').delay(3000).animate({
        left: parseInt($('.side-res-widget').css('left'),10) == 0 ?
            -$('.side-res-widget').outerWidth() :
            0
    });

But unsure how to only trigger this if nothing has been interacted with inside the popout. 但是不能确定如何仅在弹出窗口内部没有任何交互时触发此操作。

You can create a setTimeout() event, and a control variable to see if is "interacted". 您可以创建一个setTimeout()事件和一个控制变量以查看是否被“交互”。 If not, setTimeout will run normally. 否则, setTimeout将正常运行。 Something like: 就像是:

var interacted = false;

$('#myPopup').on("click", function() {
    interacted = true;
});

setTimeout(function() {
    if(!interacted) {
        //Hide process
    }
}, 3000);

Where '#myPopup' is your popup element, any interaction would trigger the click event. '#myPopup'是您的弹出元素的情况下,任何交互都会触发click事件。

暂无
暂无

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

相关问题 我如何使getSelectedCurrency仅在使用选项填充了select元素时运行 - How do I make getSelectedCurrency run only when the select element has been populated with options 如何在单击其他元素时显示元素? - How do I show an element when another element has already been clicked? 如何缩放带有动画的svg元素? - How do I scale an svg element with animate? 如果我只有后台脚本,如何检索已执行上下文菜单的元素? - How to retrieve the element where a contextmenu has been executed if i have only background script? 如何添加一个计数器来显示一个 div 元素被点击了多少次? - How do I add a counter to show how many times a div element has been clicked? 将元素插入DOM后,如何对元素执行jQuery函数? - How do I perform a jQuery function on an element after it has been inserted into the DOM? 如何检查文件是否已被选中 <input type=“file”> 元件? - How do I check if a file has been selected in a <input type=“file”> element? 在datepicker元素中输入日期后,如何触发角度事件 - How do i trigger an event in angular after a date has been entered in datepicker element 仅当前一个成功完成时,我如何正确触发此功能? - how do I properly fire this function only if the previous has successfully been completed? 如果requireJS模块在$上设置了全局变量,那么仅在分配了全局变量后,如何执行模块代码? - if a requireJS module sets a global on $, how do I execute the module code only when the global has been assigned?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM