Javascript 定时动画gif显示

Javascript 定时动画gif显示,javascript,jquery,animation,animated-gif,Javascript,Jquery,Animation,Animated Gif,Noob警报 我已经搜索了以前的问题,找不到这个具体的要求 对于我的艺术项目,我创建了一个动画gif,并希望它在我为其他项目创建的网站上显示/运行我的动画gif,每天仅一小时 我有一个非常类似的脚本,但我需要自动显示(每天一小时),而不是单击或步进。我可以摆脱这些阶段,但不确定用什么来取代它们 JavaScript动画 <script type="text/javascript"> <!-- var imgObj = null;

Noob警报

我已经搜索了以前的问题,找不到这个具体的要求

对于我的艺术项目,我创建了一个动画gif,并希望它在我为其他项目创建的网站上显示/运行我的动画gif,每天仅一小时

我有一个非常类似的脚本,但我需要自动显示(每天一小时),而不是单击或步进。我可以摆脱这些阶段,但不确定用什么来取代它们

JavaScript动画

  <script type="text/javascript">
     <!--
        var imgObj = null;
        var animate ;

        function init(){
           imgObj = document.getElementById('myImage');
           imgObj.style.position= 'relative'; 
           imgObj.style.left = '0px'; 
        }

        function moveRight(){
           imgObj.style.left = parseInt(imgObj.style.left) + 10 + 'px';
           animate = setTimeout(moveRight,20); // call moveRight in 20msec
        }

        function stop(){
           clearTimeout(animate);
           imgObj.style.left = '0px'; 
        }

        window.onload =init;
     //-->
  </script>


提前感谢您……

好的,首先要注意的是,您必须不时检查当前时间,以检查我们是否在您想要显示动画的特定时间

让我们举个例子:在13小时和14小时之间(下午1点和2点)-从现在起,我将使用24小时表示法

我们可以使用
间隔来检查是否已经超过13小时。我们自己选择精度。为了便于示例,假设我们每5分钟检查一次:

//Note: we could say "300000" immediately instead, but with the calculation, we can easily change it when we want to.
var gifInterval = setInterval(function() {canWeAnimateYet ();}, 5 * 60 * 1000);
我们有一个间隔,每5分钟检查一次。现在我们需要一个
标志
(或
bool
)来查看动画是否应该运行

var animateThatGif = false;
现在。。我们需要功能来检查时间:

var canWeAnimateYet = function() {
    //Checks here.
}
在该函数上,我们需要检查currenttime。如果超过13但在14小时之前,我们需要将标志设置为
true
,否则它将保持
false

var canWeAnimateYet = function() {

     //Get current time
     //Note: "new Date()" will always return current time and date.
     var time = new Date();

     //Note: getHours() returns the hour of the day (between 0 and 23 included). Always in 24h-notation.
     if (time.getHours() >= 13 && time.getHours < 14)
        animateThatGif = true;
     else
        animateThatGif = false;
}
var canWeAnimateYet=function(){
//获取当前时间
//注意:“new Date()”将始终返回当前时间和日期。
变量时间=新日期();
//注意:getHours()返回一天中的小时数(包括0到23之间)。始终使用24小时表示法。
如果(time.getHours()>=13&&time.getHours<14)
animatethatgf=true;
其他的
animatethatgf=false;
}

好的,首先要注意的是,您必须不时检查当前时间,以检查我们是否在您想要显示动画的特定时间

让我们举个例子:在13小时和14小时之间(下午1点和2点)-从现在起,我将使用24小时表示法

我们可以使用
间隔来检查是否已经超过13小时。我们自己选择精度。为了便于示例,假设我们每5分钟检查一次:

//Note: we could say "300000" immediately instead, but with the calculation, we can easily change it when we want to.
var gifInterval = setInterval(function() {canWeAnimateYet ();}, 5 * 60 * 1000);
我们有一个间隔,每5分钟检查一次。现在我们需要一个
标志
(或
bool
)来查看动画是否应该运行

var animateThatGif = false;
现在。。我们需要功能来检查时间:

var canWeAnimateYet = function() {
    //Checks here.
}
在该函数上,我们需要检查currenttime。如果超过13但在14小时之前,我们需要将标志设置为
true
,否则它将保持
false

var canWeAnimateYet = function() {

     //Get current time
     //Note: "new Date()" will always return current time and date.
     var time = new Date();

     //Note: getHours() returns the hour of the day (between 0 and 23 included). Always in 24h-notation.
     if (time.getHours() >= 13 && time.getHours < 14)
        animateThatGif = true;
     else
        animateThatGif = false;
}
var canWeAnimateYet=function(){
//获取当前时间
//注意:“new Date()”将始终返回当前时间和日期。
变量时间=新日期();
//注意:getHours()返回一天中的小时数(包括0到23之间)。始终使用24小时表示法。
如果(time.getHours()>=13&&time.getHours<14)
animatethatgf=true;
其他的
animatethatgf=false;
}

我不知道你在问什么。。问题是时间检测吗?是的,我想是的。我需要每24小时显示一小时的gif。我不知道你在问什么。。问题是时间检测吗?是的,我想是的。我需要gif在每个24小时内显示一个小时。谢谢你……这对我很有帮助,也很有效。感谢你花时间和精力。。Regards@giveimtamongo如果它对你有帮助,请考虑投票,并把它标记为答案:“谢谢你……这有助于治疗。”感谢你花时间和精力。。Regards@giveimtamongo如果它对你有帮助,请考虑投票,并将其标记为答案: