最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - HTML 5 Skew code - Stack Overflow

programmeradmin2浏览0评论

I need to simulate the effect of skewing an image, like Photoshop, using Javascript. Do you guys know how to do that in Javascript?

What kind of geometry calculation is applied to the <canvas> context? I can't use CSS for this, because it has to be modified dynamically.

I need to simulate the effect of skewing an image, like Photoshop, using Javascript. Do you guys know how to do that in Javascript?

What kind of geometry calculation is applied to the <canvas> context? I can't use CSS for this, because it has to be modified dynamically.

Share Improve this question edited Jul 16, 2012 at 20:53 ThinkingStiff 65.4k30 gold badges147 silver badges241 bronze badges asked Jul 16, 2012 at 19:17 DuckDuck 36.1k48 gold badges268 silver badges490 bronze badges 2
  • This can be done with CSS3 alone. – Madara's Ghost Commented Jul 16, 2012 at 19:24
  • this cannot be done with CSS because it has to be modified on the fly by javascript. I said that on the question. Thanks anyway. – Duck Commented Jul 16, 2012 at 20:43
Add a ment  | 

3 Answers 3

Reset to default 2

This is possible with CSS3 alone:

img {
  -webkit-transform: skew(45deg);
}

Live Example

Note, I only used webkit, but it's the same for all other modern browsers.

CSS transform: skew(); will do this for you with no Javascript.

Demo: http://jsfiddle/ThinkingStiff/MtWBy/

Output

CSS

#original {
    margin: 55px 10px 0 10px;
}

#vertical {
    margin: 30px 20px 0 0;
    transform:             skew( 0, -30deg );
        -ms-transform:     skew( 0, -30deg );
        -moz-transform:    skew( 0, -30deg );
        -o-transform:      skew( 0, -30deg );
        -webkit-transform: skew( 0, -30deg );
}

#horizontal {
    margin: 55px 0 0 0;
    transform:             skew( -30deg, 0 );
        -ms-transform:     skew( -30deg, 0 );
        -moz-transform:    skew( -30deg, 0 );
        -o-transform:      skew( -30deg, 0 );
        -webkit-transform: skew( -30deg, 0 );
}

.image {
    background-image: url( 'http://placekitten./100' );  
    border: 1px solid black;
    display: inline-block;
    height: 100px;
    margin-right: 20px; 
    vertical-align: top;
    width: 100px;  
}

HTML

<div id="original" class="image"></div>
<div id="vertical" class="image"></div>
<div id="horizontal" class="image"></div>

I found the solution: http://www.w3schools./html5/playcanvas.asp?filename=playcanvas_transformb&preval=1,0,0,1,0,0

发布评论

评论列表(0)

  1. 暂无评论