我试图使用jQuery:
经检查后:
我的代码不起作用-目前似乎什么都不做.控制台中没有要诊断问题的错误。此外,我怀疑有一个更简单的方法来达到预期的结果。
非常感谢你帮我解决这个问题。
$(document).ready(function() {
var windowWidth = $(window).width();
var lineBreakLength = $('#lineBreak').length;
if (windowWidth >= 2400 && lineBreakLength == 0) {
$('#container-3').after('<br id="lineBreak">');
console.log('Window width greater than 2400px. Added <br> tag.');
} else if (windowWidth < 2400 && lineBreakLength > 0) {
$('#lineBreak').remove();
console.log('Window width less than 2400px. Removed <br> tag.');
}
});
$(window).resize(function() {
var windowWidth = $(window).width();
var lineBreakLength = $('#lineBreak').length;
if (windowWidth >= 2400 && lineBreakLength == 0) {
$('#container-3').after('<br id="lineBreak">');
console.log('Window width greater than 2400px. Added <br> tag.');
} else if (windowWidth < 2400 && lineBreakLength > 0) {
$('#lineBreak').remove();
console.log('Window width less than 2400px. Removed <br> tag.');
}
});发布于 2016-03-30 20:58:18
@media only screen and (min-width: 2400px) {
.break {display:none;}
}现在在html中:
<br class="break" />这是DEMO
请注意,为了方便测试,我在演示中将2400更改为600。
但是,如果您坚持使用jQuery(不建议这样做):
if($(document).width() <=2400)
$('.break').css('display','block');
else
$('.break').css('display','none');https://stackoverflow.com/questions/36319424
复制相似问题