English 中文(简体)
• 如何产生类似于WWaW的冷却效应?
原标题:How to create a WoW-like cooldown effect?
最佳回答

This is what I came up with. Basically what it does is, it encapsulates an image and a 0.5 opacity canvas on top of each other in a composite widget. The animation draws lines on the canvas from the center towards the edges in a circular fashion in a given time interval. Canvas has a clickHandler to start the animation. Hope it helps. It uses GWT Canvas so this widget may not be supported on all browsers.

Class:

    public class CoolDownAnimation extends Animation {

    Canvas canvas;
    Context2d context;
    int centerX;
    int centerY;
    static final CssColor BLACK = CssColor.make("rgba(0,0,0,0.6)");
    static final CssColor WHITE = CssColor.make("rgba(255,255,255,0.6)");

    public CoolDownAnimation(Canvas canvas) {
        this.canvas = canvas;
        canvas.setCoordinateSpaceHeight(20);
        canvas.setCoordinateSpaceWidth(20);
        canvas.getElement().getStyle().setOpacity(0.5);
        this.context = canvas.getContext2d();
        centerX = canvas.getCoordinateSpaceWidth() / 2;
        centerY = canvas.getCoordinateSpaceHeight() / 2;
    }
    @Override
    protected void onStart() {
        context.beginPath();
        context.setStrokeStyle(BLACK);
        context.fillRect(0, 0, centerX * 2, centerY * 2);
        context.setStrokeStyle(WHITE);
        super.onStart();
    }
    @Override
    protected void onUpdate(double progress) {
        context.moveTo(centerX, centerY);
        context.lineTo(
                centerX + 2 * centerX * Math.cos((progress * Math.PI * 2)-Math.PI/2),
                centerY + 2 * centerY * Math.sin((progress * Math.PI * 2)-Math.PI/2));
        context.stroke();
    }   
    @Override
    protected void onComplete() {
        super.onComplete();
        context.closePath();
        context.clearRect(0, 0, centerX*2, centerY*2);
    }
}

Class CoolDownWidget :

    public class CoolDownWidget extends Composite {

    private CoolDownAnimation coolDown;
    private AbsolutePanel wrapper;
    private Image image;
    private Canvas canvas;
    private int sizeX = 50;
    private int sizeY = 50;
    private int coolDownDuration = 5000;

    public CoolDownWidget(){
        canvas = Canvas.createIfSupported();
        if (canvas==null){
            Window.alert("Fail! You dont have canvas support");
        }
        canvas.getElement().getStyle().setOpacity(0.5);
        canvas.setPixelSize(sizeX,sizeY);
        coolDown = new CoolDownAnimation(canvas);
        image = new Image("images/icon.png");
        image.setPixelSize(sizeX, sizeY);
        canvas.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                coolDown.cancel();
                coolDown.run(coolDownDuration);
            }
        });
        wrapper = new AbsolutePanel();
        wrapper.setPixelSize(sizeX, sizeY);
        wrapper.add(image, 0, 0);
        wrapper.add(canvas,0,0);
        initWidget(wrapper);
    }
}

最后,ModuleLoad总结:

    public void onModuleLoad() {
    RootPanel.get().add(new CoolDownWidget());
}
问题回答

这是一种使用杂草的 j/c。

参见:http://codepen.io/anon/pen/aZzNbY'rel=“nofollow”http://codepen.io/anon/pen/aZNbY

    <html>
      <head>
          <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
          <style type="text/css">
            .box{
                width:128px;
                height:128px;
                background-color:black;
                overflow:hidden;
                padding:5px;
                border:4px solid #ddd;
                border-radius:12px;
                position:relative;
            }

            input[type="submit"] {
                width: 100%;
                height: 100%;
                border: 0;
                background: url( http://icons.iconseeker.com/png/fullsize/smoothicons-12/warcraft-1.png ) no-repeat ;
            }

            .cooldown{
                position:absolute;
                top:5%;
                left:5%;
                width:90%;
                height:90%;
                overflow:hidden;
                opacity:0;
            }   

            .cooldown-half{
                width:50%;
                height:100%;
                overflow:hidden;
                position:relative;
                float:left;
            }

            .cooldown-half-rotator{
                width:200%;
                height:200%;
                top:-50%;
                position:absolute;
                background-color:rgba(1,1,1,0.5);
            }

            .cooldown-half-rotator-right{
                transform-origin:left center;
            }

            .cooldown-half-rotator-left{
                right:0;
                transform-origin:right center;
            }


          </style>
      </head>
      <body>
          <div class= box >
              <input   type="submit" value="" ><div></div></input>
              <div class= cooldown >

                  <div class= cooldown-half >
                      <div class= cooldown-half-rotator cooldown-half-rotator-left >
                      </div>                         
                  </div>            
                  <div class= cooldown-half >
                      <div class= cooldown-half-rotator cooldown-half-rotator-right >           
                      </div>                              
                  </div>            

              </div>
          </div>
          Click me

          <script>
              function setCooldown( time, stopper ){
                    $(".cooldown").css({"opacity":1});
                        $(".cooldown-half-rotator-right").css({
                            "transform":"rotate(180deg)",
                            "transition":"transform "+(time/2000)+"s",
                            "transition-timing-function":"linear"
                        });
                        setTimeout( function(){
                            $(".cooldown-half-rotator-left").css({
                                "transform":"rotate(180deg)",
                                "transition":"transform "+(time/2000)+"s",
                                "transition-timing-function":"linear"
                            });
                            setTimeout( function(){
                                $(".cooldown-half-rotator-right").css({"transform":"rotate(0deg)","transition":"transform 0s"});
                                $(".cooldown-half-rotator-left").css({"transform":"rotate(0deg)","transition":"transform 0s"});
                                $(".cooldown").css({"opacity":0});
                            }, time/2 );
                        }, time/2 );
              }
              window.onload = function(){
                  $(".box").click(function(){                        
                      setCooldown( 3000 );
                  });
              }
          </script>
      </body>
    </html>

页: 1 Jquery rotate

参看example 3

Alternatively: you could divide the square into little pie-slices (a bit hard to see, but like this pizza). Make a transparant image for each one, and just show/hide them in order one by one using jquery. This is probably the easiest and fastest solution.

手枪提议的解决方案的另一个变化 最新方法的潘数:

this.context.clearRect(0, 0, this.width, this.height);

// Black background
this.context.setFillStyle(BLACK);
this.context.fillRect(0, 0, this.width, this.height);

// White to show the progress
this.context.setFillStyle(WHITE);
this.context.beginPath();
this.context.moveTo(this.centerX, this.centerY);
this.context.arc(this.centerX, this.centerY, this.width, -Math.PI / 2, 2 * Math.PI * progress - Math.PI / 2, false);
this.context.lineTo(this.centerX, this.centerY);
this.context.fill();
this.context.closePath();

它的好处是,它把白白白白白白白白白白化,并填满。 这确保了该地区总是有适当的颜色,从而更能抵御浏览器的减缓。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签