jQuery 重新调整大小
我有这段代码,它允许我在浏览器调整大小时更改样式表:
$(window).resize(function () {
var width = $(window).width();
var height = $(window).height();
if ((width <= 1280) && (height <= 800)) {
$("link[rel=stylesheet]:not(:first)").attr({ href: "Styles/Home-1024.css" });
}
else if ((width > 1280) && (height > 800)) {
$("link[rel=stylesheet]:not(:first)").attr({ href: "Styles/Home.css" });
}
});
它工作正常,但我试图在浏览器返回到其原始大小时再次更改样式表。
I have this code which allows me to change the style sheet when the browser is re-sized:
$(window).resize(function () {
var width = $(window).width();
var height = $(window).height();
if ((width <= 1280) && (height <= 800)) {
$("link[rel=stylesheet]:not(:first)").attr({ href: "Styles/Home-1024.css" });
}
else if ((width > 1280) && (height > 800)) {
$("link[rel=stylesheet]:not(:first)").attr({ href: "Styles/Home.css" });
}
});
and it works fine but i am trying to change the style sheet again when the browser returns to its original size.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以尝试:
You can try:
我认为部分问题在于脚本在每次拖动的每个时刻都会触发。
您可以考虑添加延迟,以便事件不会重复多次。
请参阅:JavaScript/JQuery:$ (window).resize 如何在调整大小完成后触发?
I think part of the problem is that the script fires at each moment of each drag.
You might consider adding a delay so that the event is not repeated so many times.
See this: JavaScript/JQuery: $(window).resize how to fire AFTER the resize is completed?
我缺少一个大于此的两倍而不是这个:
我使用了这个并且它有效:
i was missing a double greater than so instead of this :
i used this and it worked: