我想使此功能僅在屏幕尺寸高於1024像素時才起作用。使功能在特定的寬度上工作
//Parallax background image
var velocity = 0.5;
function update(){
var pos = $(window).scrollTop();
$('.parallax').each(function() {
var $element = $(this);
var height = $element.height();
$(this).css('background-position', '40%' + Math.round((height - pos) * velocity) + 'px');
});
};$(window).bind('scroll', update); update();
這是我試圖做:
//Parallax background image
var velocity = 0.5;
$(window).on("ready resize", function() {
if ($(window).width() < 770) {
function update(){
var pos = $(window).scrollTop();
$('.parallax').each(function() {
var $element = $(this);
var height = $element.height();
$(this).css('background-position', '40%' + Math.round((height - pos) * velocity) + 'px');
});
};});$(window).bind('scroll', update); update();
我真的不知道我在做什麼錯?
根據您的要求,您的條件應該是'if($(window).width()> 1024){' –
呵呵,現在改變這個 – Leo
仍然沒有做任何事 – Leo