var fontSize = $('.basic_unit').css('font-size');
if (fontSize == '6px') {docHeight=32000;} else if (fontSize == '8px') {docHeight=48000;} else { docHeight = 11000; }
var winWidth = $(window).width();
if (winWidth <= 700){
$('.basic_unit').css.('font-size','2px')
}
else if (winWidth > 701 && winWidth <= 1200) {
$('.basic_unit').css.('font-size','6px')
}
else
$('.basic_unit').css.('font-size','8px');
var variableXXX = false;
$(window).scroll(function() {
var scrollPercent = 100 * $(window).scrollTop() / docHeight;
if ( scrollPercent >= 5 && variableXXX == false){
variableXXX = true;
alert($(document).scrollTop());
}
});
&#13;
我需要使用此代码,如标题中所述:
之后:
之后:
答案 0 :(得分:3)
$(window).resize(function(){
var winWidth = $(window).width();
if (winWidth <= 700){
$('.basic_unit').css('font-size','2px')
}
else if (winWidth > 701 && winWidth <= 1200) {
$('.basic_unit').css('font-size','6px')
}
else
$('.basic_unit').css('font-size','8px');
});
但我建议使用css media避免使用Javascript:
@media screen and (max-width: 700px) {
.basic_unit {font-size:2px}
}
@media screen and (min-device-width: 701px) and (max-device-width: 1200px) {
.basic_unit {font-size:6px}
}
@media only screen and (min-device-width: 1021px) {
.basic_unit {font-size:8px}
}
答案 1 :(得分:0)