我有这个脚本:



<script>
jQuery(function($){
    if (!$('#et-info').length) {
         $('#top-header .container').prepend('<div id="et-info"></div>');
    }
    $('#et-info').prepend('<span style="margin:0 10px">NYITVATARTÁS: H-Sz 10-19, V 10-16</span>');
})
	</script>





我只想在移动设备上启用它。

最佳答案

您可以使用JavaScript检查视口宽度。

jQuery(document).ready(function($) {
    const viewportWidth = window.innerWidth;
    if (viewportWidth < 640) {
        if (!$('#et-info').length) {
            $('#top-header .container').prepend('<div id="et-info"></div>');
        }
        $('#et-info').prepend('<span style="margin:0 10px">NYITVATARTÁS: H-Sz 10-19, V 10-16</span>');
    }
});

08-18 14:24
查看更多