我想检查浏览器是否具有相应的像素大小。这是我的尝试:
var height = $(".size_fullscreen").height();
var width = $(".size_fullscreen").width();
if (height == 1024 && width == 768) {
alert("please flip");
}
起初对我有用,但现在我想要一直查看这个脚本。因此,如果尺寸发生变化,应该弹出类似“谢谢”的东西。
我认为jquery中有文件就绪函数,但我没有得到它的解决方案。
任何人都可以帮助我吗?谢谢!
答案 0 :(得分:3)
试试这个
$document.ready(function(){
/** Functions to call on Window Resize**/
var ResizeTimer;
$(window).on("resize", function(){
clearTimeout(ResizeTimer);
ResizeTimer = setTimeout(function(){
// Add your functions here
var wH = $(".size_fullscreen").height();
var wW = $(".size_fullscreen").width();
if (wH == 1024 && wW == 768) {
alert("please flip");
}
// wait for 200ms between each resize event
},200);
});
// Call your function on DOM ready / Trigger resize
$(window).trigger('resize');
});
答案 1 :(得分:2)
如果你想检查你总是写的脚本,那就把它放在窗口调整大小事件中。
示例:
$(window).resize(function() {
var height = $(window).height();
var width = $(window).width();
if (height == 1024 && width == 768) {
alert("please flip");
}
});