用svg实现不规则形状

像这种弧形,用纯html和css很难写,但是用svg就简单多了。

可以用作图工具画出一个弧形,然后导成svg格式。在页面中,下面的白块就是div+svg构成

 1 mixin svgCard(...cont)
 2     each item in cont
 3         .item
 4             svg.svg(width="480px" height="132px" viewBox="0 0 480 132")
 5                 path(d="M0 31c109.323 19.23 189.323 28.845 240 28.845 50.677 0 130.677-9.615 240-28.845v100H0V31z" fill="white")
 6             .detail
 7                 .txt!= item[0]
 8 
 9 .content
10     +svgCard(
11         ['百年严谨的学风传统'],
12         ['全球顶级大学的主要输送处']
13                           

(这里用的是pug模板)


 

两种弧度的切换,主要是在hover的时候修改path值即可(注意两个svg大小一样

1 $('.content .item').hover(function(){
2         $(this).find('path').attr('d','M0 31.398C109.323 10.466 189.323 0 240 0c50.677 0 130.677 10.466 240 31.398V131.52H0V31.398z')
3     },function(){
4         $(this).find('path').attr('d','M0 31c109.323 19.23 189.323 28.845 240 28.845 50.677 0 130.677-9.615 240-28.845v100H0V31z')
5 
6     })

 

如果不写过渡css,这两种弧形的切换会比较僵硬。(注意过渡css是写在path上而不是svg上)

 1 path,.txt{
 2     transition: all 500ms ease;
 3 }
 4 
 5 .item:hover{
 6     path{
 7         transition: all 500ms ease;
 8     }
 9     .txt{
10         transition: all 500ms ease;
11         transform: translateY(-15px);
12     }
13 }    

 

posted @ 2018-08-27 17:31  *茉莉花开*  阅读(1848)  评论(0编辑  收藏  举报