douwen3965 2015-05-02 01:33 采纳率: 0%
浏览 39
已采纳

点击,减少倒计时与1等等,当倒计时达到0打开窗口

If the downvoters could leave a reason. That'd be great.

Lets say I have a value of 10 on my web page, and a button.

Every time a user clicks on this button, I want to have a visual indication of the value decreasing by 1.

When value is 0 (after 10 clicks) it will hide a div, and show another one.

However when clicking the button, not only the counter needs to reduce by 1 but it also needs to open a window. (It's the same window every click)

On every click I'd also like to change style="width:x%"`` with 10-20-30% and so forth. (But with a delay of 5 seconds)

Does anyone have an idea on how to do all of this, without going overboard on the amount of code.

Here the steps:

  • Click button
  • Window opens
  • Counter goes from 10 to 9
  • After 5 seconds have passed the progress bar's style switches to
    width: 10%;

...

Counter reaches 0:

  • Hide div X (fadeout)
  • Show div X

source code:

function countdown() {
    var i = document.getElementById('counter');
    if (parseInt(i.innerHTML)<=0) {
        //hide div
        //show div
    }
    i.innerHTML = parseInt(i.innerHTML)-1;
    window.open("");
    //change loader
}
  • 写回答

1条回答 默认 最新

  • duanshan188866 2015-05-02 04:52
    关注

    This code is maybe the solution you wanted:

    function countdown() {
      var i = document.getElementById('counter');
      if (parseInt(i.innerHTML)<=0) {
        $("#counter").fadeout();
        i.innerHTML =10;
        i.style.width="100%";
        $("#counter").fadein(10);
      } else {
        i.innerHTML = parseInt(i.innerHTML)-1;
        setTimeout(function(){
          var i = document.getElementById('counter');
          i.style.width="10%";
          i.innerHTML="1";
        },5000)
      }
      var msg = window.open("", "Window name", "width=200, height=100");
      msg.document.write("Some HTML");
    }
    

    You have to add jquery in the html head! Leave a comment if the code doesn't help.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型