【问题标题】:How do I multiply with 0.8 in JavaScript如何在 JavaScript 中乘以 0.8
【发布时间】:2018-08-20 14:50:41
【问题描述】:

2020 年编辑:我又年轻又笨,不知道乘法是如何工作的。

所以,我需要在网站上嵌入一个 youtube 视频,并且我希望它占据用户屏幕大小的 80%。我找到以下代码使其全屏显示。有人可以帮我把它全屏 -20% 吗?

    $(function(){
  $('#video').css({ width: $(window).innerWidth() + 'px', height: $(window).innerHeight() + 'px' });

  $(window).resize(function(){
    $('#video').css({ width: $(window).innerWidth() + 'px', height: $(window).innerHeight() + 'px' });
  });
});

【问题讨论】:

  • 你是问如何乘以0.8
  • @Amy 是的,我是。我已经更新了问题。

标签: javascript


【解决方案1】:

windowwidthheight 乘以0.8,得到全屏宽度和高度的80%。

$(function(){
  $('#video').css({ width: $(window).innerWidth()*0.8 + 'px', height: $(window).innerHeight()*0.8 + 'px' });

  $(window).resize(function(){
    $('#video').css({ width: $(window).innerWidth()*0.8 + 'px', height: $(window).innerHeight()*0.8 + 'px' });
  });
});

【讨论】:

  • 谢谢。这工作得很好,我试图把它分开,但没有奏效。
  • @FCD 没问题。
【解决方案2】:

我认为你有宽度:$(window).innerWidth() + 'px'... 你是说让宽度成为页面的整体,与高度相同。

你能把$(window).innerWidth()除以一定的大小,比如300吗? 这可能会为您改变视频的大小。

如:

var smallerWidthWindow = window.innerHeight / 250; //(or required number)

然后有宽度:smallerWidthWindow 和 height:smallerHeightWindow,使用这些变量来改变你的高度和宽度。

$('#video').css({ width: smallerWidthWindow, height: smallerHeightWindow });

【讨论】:

    猜你喜欢
    • 2015-11-21
    • 1970-01-01
    • 1970-01-01
    • 2017-11-19
    • 2015-01-28
    • 2016-10-25
    • 1970-01-01
    • 1970-01-01
    • 2016-07-04
    相关资源
    最近更新 更多