<html>
<head>
</head>
<body>
<svg style="width:100%;height:250px;margin:0;padding:0;">
//绘制背景方框,大小为50*6400
<path d="M0 110v50h6400v-50z" stroke="#fff" style="fill:#529BB3;stroke-width:0px;"></path>
//绘制二次贝塞尔曲线,q的控制点为(50,20),其后跟随的t会自动对称该控制点,因此t命令中只要指定结束点即可
<path id="wave1" d="M0 110q50 20,100 0t100 0t100 0t100 0t100 0t100 0t100 0t100 0t100 0t100 0t100 0t100 0t100 0t100 0t100 0" stroke="#fff" style="fill:lightblue;stroke-width:1px;"></path>
</svg>
<script>
(function(){
//利用正则获取传入元素的控制点高度并返回
var getHeight=function($ele){
var path=$ele.getAttribute('d');
var height=parseInt(/q\d{2}\s(\-*\d{1,2})/.exec(path)[1]);
return height;
};
//时间控制主函数
var myTimer=function(id,callback){
var $ele=document.querySelector(id);
//利用前面的函数获取高度
var height=getHeight($ele);
var num=height;
//高度递减时flag为true
var flag=true;
setInterval(function(){
if (flag) {
height--;
//如果高度达到最低点,则flag设为false,高度开始递增
if (height <= -num) {flag = false;}
} else {
height++;
if (height >= num) {flag = true;}
};
//调用回调函数,改变元素属性值
callback($ele,height);
},50);
};
var changeHeight=function($ele,val){
//利用正则提取元素控制点高度
var array=$ele.getAttribute('d').split(/(q\d{2}\s)(\-*\d{1,2})/);
//改变控制点高度
array[2]=val;
//给元素写入改变后的高度
$ele.setAttribute('d',array.join(''));
};
//执行主函数
myTimer('#wave1',changeHeight);
})();
</script>
</body>
</html>
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |