我正在制作一个响应性的网站,我有一个视频背景为第一个屏幕,我想隐藏在移动设备上的视频,以使网站加载更快。确定显示:无;不会禁用内容下载。我尝试使用这两个javascript来禁用内容,使其无法在较小的屏幕上加载内容,但它仍然加载在后台:
if (screen.width < 768){
var removeelement = document.getElementById("videoClass");
removeelement.innerHTML = "";
}
或:
$("#videoClass").remove();
他们做同样的工作CSS标签:显示-无。在javascript中有什么方法可以阻止内容在后台加载吗?
发布于 2015-10-18 10:32:07
我认为解决这一问题的唯一方法是像Laxmikant Dange和VanderVidi所说的那样,所有的javascripts和jqueries都很好,而且工作正常,但问题在于我如何加载视频。我使用这段代码仅在width>768屏幕上下载内容
<video id="videoClass">
<!-- removed the content from here -->
</video>
<script>
$(document).ready(function() {
if (screen.width > 768){
var showElement = document.getElementById("videoClass");
//pasted the content here:
showElement.innerHTML = '<source src="video.mp4" type="video/mp4">';
}
});
</script>
这解决了问题,现在内容只能在大屏幕上加载。非常感谢你的帮助。
发布于 2015-10-18 09:42:21
添加下面的代码,这将使所选div的html为空。
if(window.innerWidth < 768 )//screen.width < 768
{
$("#videoClass").html("");
}
发布于 2015-10-18 09:49:16
您可以使用:
if (screen.width < 768){
$("#videoClass").empty();
}
https://stackoverflow.com/questions/33196453
复制相似问题