Javascript 仅在桌面版本中加载图像

Javascript 仅在桌面版本中加载图像,javascript,html,css,responsive-design,Javascript,Html,Css,Responsive Design,在网站上,我只想在用户在笔记本电脑或台式机上查看页面时加载我的背景图像。在移动版本中,我不希望图像显示,此外(!)我不希望加载它 实现这一点的最佳方法是什么?尝试下面的方法,使bg图像的使用取决于屏幕大小。您可以为另一个屏幕大小设置下面示例的另一个块 @media screen and (max-width: 768px) { /* Adjust as needed */ body { /* The element or whatever */ background-im

在网站上,我只想在用户在笔记本电脑或台式机上查看页面时加载我的背景图像。在移动版本中,我不希望图像显示,此外(!)我不希望加载它


实现这一点的最佳方法是什么?

尝试下面的方法,使bg图像的使用取决于屏幕大小。您可以为另一个屏幕大小设置下面示例的另一个块

@media screen and (max-width: 768px) { /* Adjust as needed */
    body { /* The element or whatever */
        background-image: none;
    }
    }
使用css:

//default css
    body{
        background-image:url(images/image_de_fond.png);
    }

    @media screen and (max-width: 640px) {
    // for screen under 640px width the following css will be applied
        body{
            background-image:none;
        }
    }

不需要
!重要信息
。。如果他们需要的话,只会让OP在以后更难覆盖这个