我一直在尋找在網站上使用媒體查詢,但螺栓下載一個巨大的文件只爲它的想法需要年齡在iPhone上通過3G下載。媒體查詢圖像文件名稱在屏幕上的大小更改
當在iphone/netbook/ipad上查看網站時,是否有可能使用jquery更改文件名(即添加-iphone到background.jpg以製作background-iphone.jpg) 。
在我的腦海中,似乎應該有可能。這將會是巨大的,如果有任何人可以事先做出來太:-D
感謝
STU
我發現這個代碼,發現屏幕尺寸
$(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");
}