Javascript 媒体查询图像文件名更改屏幕大小
我一直在考虑在一个网站上使用媒体查询,但是我突然想到了一个想法,那就是下载一个巨大的文件只需要花很长时间才能通过3G下载到iphone上 当在iphone/netbook/ipad上查看站点时,是否可以使用jquery更改文件名(例如,将-iphone添加到background.jpg以生成后台iphone.jpg),可能也会使用其中的媒体查询 在我看来这应该是可能的。如果有人也能解决这个问题那就太好了 提前谢谢 斯图 我找到了查找屏幕大小的代码Javascript 媒体查询图像文件名更改屏幕大小,javascript,jquery,mobile-phones,media-queries,Javascript,Jquery,Mobile Phones,Media Queries,我一直在考虑在一个网站上使用媒体查询,但是我突然想到了一个想法,那就是下载一个巨大的文件只需要花很长时间才能通过3G下载到iphone上 当在iphone/netbook/ipad上查看站点时,是否可以使用jquery更改文件名(例如,将-iphone添加到background.jpg以生成后台iphone.jpg),可能也会使用其中的媒体查询 在我看来这应该是可能的。如果有人也能解决这个问题那就太好了 提前谢谢 斯图 我找到了查找屏幕大小的代码 $(document).ready(functi
$(document).ready(function() {
if ((screen.width>=1024) && (screen.height>=768)) {
alert('Screen size: 1024x600 or larger');
$("link[rel=stylesheet]:not(:first)").attr({href : "detect1024.css"});
}
else {
alert('Screen size: less than 1024x768, 800x600 maybe?');
$("link[rel=stylesheet]:not(:first)").attr({href : "detect800.css"});
}
});
我发现了这个脚本,我认为它可以将文本添加到文件中
$('.rollover').hover(
function(){ // Change the input image's source when we "roll on"
var t = $(this);
t.attr('src',t.attr('src').replace(/([^.]*)\.(.*)/, "$1-over.$2"));
},
function(){
var t= $(this);
t.attr('src',t.attr('src').replace('-mobile',''));
}
);
有没有办法把两者结合起来
也许是这样的-
$(document).ready(function() {
if ((screen.width>=1024) && (screen.height>=768)) {
var t= $(this);
t.atter('src',t.attr('src').replace('-mobile',''))
}
);
但不知道如何修复语法错误
或者这个-仍然有结尾语法错误
$(document).ready(function() {
if ((screen.width>=1024) && (screen.height>=768)) {
var re = new RegExp("(.+)_hover\\.(gif|png|jpg)", "g");
return filename.replace(re, "$1.$2");
}
这是可能的,也不太难实现。但为了简单起见,为什么不使用以下内容:
$(document).ready(function() {
if ((screen.width<=960) && (screen.height<=640)) {
$("#someid").addClass("iphone");
}
});
$(文档).ready(函数(){
如果((screen.width这是可能的,而且也不太难实现。但是为了简单起见,为什么不使用以下内容:
$(document).ready(function() {
if ((screen.width<=960) && (screen.height<=640)) {
$("#someid").addClass("iphone");
}
});
$(文档).ready(函数(){
如果((屏幕宽度或有关允许您使用图像标签的解决方案,请参阅以下内容:
$(document).ready(function() {
if ((screen.width<=960) && (screen.height<=640)) {
$("img").attr("src", $("img").attr("src").replace(/([^.]*)\.(.*)/, "$1-iphone.$2"));
}
});
$(文档).ready(函数(){
如果((屏幕宽度或有关允许您使用图像标签的解决方案,请参阅以下内容:
$(document).ready(function() {
if ((screen.width<=960) && (screen.height<=640)) {
$("img").attr("src", $("img").attr("src").replace(/([^.]*)\.(.*)/, "$1-iphone.$2"));
}
});
$(文档).ready(函数(){
如果((屏幕宽度