[英]jQuery Slice resize function
I need a script that makes: 我需要一个脚本,使:
if screen bigger than 480px then do this 如果屏幕大于480px,那么这样做
(".projects").slice(3, 6).css("margin", "10px");
if screen between 320px and 480px then do this 如果屏幕在320px和480px之间,那么这样做
$(".projects").slice(1, 8).css("margin", "10px");
I saw some scripts but did not really understand how to make this. 我看到了一些脚本,但并不真正理解如何制作它。 Can anyone help me with this please? 有人可以帮我这个吗?
I need to do this JavaScript because the slice only works with js. 我需要做这个JavaScript,因为切片只适用于js。 I can't do this with css. 我不能用css这样做。
Here it is: 这里是:
var width = screen.width;
if (width >= 320 && width <= 480) {
$(".projects").slice(1, 8).css("margin", "10px");
} else if (width > 480) {
$(".projects").slice(3, 6).css("margin", "10px");
}
To use the window size, use this: 要使用窗口大小,请使用:
var width = $(window).width();
To do this dinamically on window resize: 要在窗口调整大小的情况下执行此操作:
$(window).resize(function () {
var width = $(window).width();
$(".projects").css("margin", 0); // you may want to do this to "reset"
if (width >= 320 && width <= 480) {
$(".projects").slice(1, 8).css("margin", "10px");
} else if (width > 480) {
$(".projects").slice(3, 6).css("margin", "10px");
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.