好的,所以我創建了自己的parallaxing jQuery/JS腳本,但我不知道如何定位支持以下(需要以下)的瀏覽器:視差/背景位置特徵檢測
- 支持背景位置
網站(預覽),我想這就是在轉型: My Test Site
我如何可以檢測瀏覽器是否支持,雖然這? 我可以根據窗口寬度運行媒體查詢嗎? 我必須瀏覽器嗅探嗎? 我在WWW上看不到任何東西,它提供了有關如何爲此進行功能檢測的線索。
任何幫助將不勝感激。
我的JS代碼是在這裏:(請隨時使用它,如果你喜歡它)
var goTop = 0;
var thisGoTop = 0;
var thisHeight = 0;
var thisWinH = 0;
var bottomIntrusion = 0;
var thisMax = 0;
var bgPos = 0;
function parallax(){
goTop = $(window).scrollTop();
thisWinH = $(window).height();
$('div.para').each(function(){
thisGoTop = $(this).offset().top;
thisHeight = $(this).height();
thisMax = Math.floor(thisHeight * 0.3);
bottomIntrusion = (thisGoTop + (thisHeight/2) - goTop)/thisWinH;
if (bottomIntrusion > 0) {
bgPos = 0 - (Math.floor(thisMax * bottomIntrusion));
$(this).css('background-position','center ' + bgPos + 'px');
}
});
}
parallax();
$(window).scroll(function(){
parallax();
});
編輯: 我進去看了Modernizr的圖書館,我還沒有發現任何東西這給了我關於CSS3的背景位置變換支持的線索。我在這一點上越來越接近嗅探者,我不想去那裏。
在http://modernizr.com/看看或更具體的這一部分:http://modernizr.com/docs/#features-css – Jimmyt1988
什麼部分詹姆斯?任何人都可以基於堅實的經驗指向正確的方向嗎? – 3Dom
啊,waddya知道......它並沒有專門在......中做到。所以你必須做什麼(並且隨意擴展modernizr庫,但是如果你是cba ..我永遠不會......等待我的答案,那應該可以完成這項工作) – Jimmyt1988