视频缩放的小脚本
本来想要随便放一个小视频的,结果丢上去之后各个浏览器显示结果很不一样,折腾了半天算了稍微顺眼一点点,为了防止以后再遇到,就放这里做个笔记,说不定什么时候又用的上呢。
<script type="text/javascript">
var ww = $(window).width();
var hh = $(window).height();
var video = $('#myVideo');
video.on('loadedmetadata', function() {
var videow = video.prop('videoWidth');
var videoh = video.prop('videoHeight');
var nn = videow/videoh;
var xw = xh = 0;
if(ww>videow && hh>videoh){
xw = videow * 0.9;
xh = videoh * 0.9;
}else if(ww/hh > nn) {
xh = hh * 0.6;
xw = xh * nn;
}else{
xw = ww * 0.95;
xh = xw / nn;
}
video.width(xw);
video.height(xh);
});
</script>