我尝试使此代码在小屏幕上运行。但我无法解决前 55.5em 的问题
$(document).on('click', '#myBtn', function () {
if ($('div.content2').hasClass("clicked")) {
$('div.content2').animate({
'top': "12.5em",
'height': "42%"
});
$('div.content2').removeClass("clicked");
} else {
$('div.content2').animate({
'height': "42%",
'top': '32.75em'
});
$('div.content2').addClass("clicked");
}
});
var smallScreen = window.matchMedia("(max-width:1024px)");
$(document).on('click', '#myBtn', function (e) {
if (smallScreen.matches) {
if ($('div.content2').hasClass("clicked")) {
$('div.content2').animate({
'top': "32.5em",
'height': "30%"
}, 1000);
$('div.content2').removeClass("clicked");
} else {
$('div.content2').animate({
'height': "auto",
'top': '55.5em'
}, 1000);
$('div.content2').addClass("clicked");
}
}
});