javascript - 在移动设备上显示内容并在桌面设备上隐藏
问题描述
我有此代码用于在网站上实现 whats 应用程序按钮,我如何仅在移动视图中显示它并在桌面视图中隐藏它?
<script type="text/javascript">
(function () {
var options = {
whatsapp: "+39 ", // WhatsApp number
call_to_action: "contacts", // Call to action
position: "right", // Position may be 'right' or 'left'
};
var proto = document.location.protocol, host = "whatshelp.io", url = proto + "//static." + host;
var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = url + '/widget-send-button/js/init.js';
s.onload = function () { WhWidgetSendButton.init(host, proto, options); };
var x = document.getElementsByTagName('script')[0]; x.parentNode.insertBefore(s, x);
})();
</script>
解决方案
您只能将 css 与media-query
例如,当浏览器窗口宽度为 600px 或更小时隐藏按钮:
@media only screen and (max-width: 600px) {
button{
display: none;
}
}
推荐阅读
- android - Android ImageView SRC 通过数据绑定
- statistics - 朱莉娅的移动平均线
- ios - 如何检查数组字符串元素是否包含数字
- imagemagick - 调用 wand.image.Image.pseudo 方法绘制文本时无法使用 pango 参数
- php - 如何对函数参数中的数字求和并减少第二个参数直到0
- wordpress - 标签页不显示日期(wordpress)
- java - 实践中的并发循环缓冲区错误?
- javascript - 如何根据某些数据更改画布元素内的颜色?
- geoserver - MapProxy + 地理服务器
- javascript - JavaScript 将小数转换为整数