开发者

jQuery masonry not working with Safari

开发者 https://www.devze.com 2023-02-05 22:57 出处:网络
I\'m using jQuery Masonry with a WordPress installation and it works fine in every browser but Safari (both Win and OSX). Could this be related to some jQuery/WebKit issues with .load() firing too ear

I'm using jQuery Masonry with a WordPress installation and it works fine in every browser but Safari (both Win and OSX). Could this be related to some jQuery/WebKit issues with .load() firing too early? I'm quite new to jQuery/JavaScript, so any help is greatly appreciated.

This page doesn't work in Safari: http://tangomitstil.de/news/

While this page (for some reason) does: http://tangomitstil.de/info/unterricht/

The problem is not related to the number of items (I'm experiencing the same problem with my dev versi开发者_开发知识库on with a rather large set of test posts), @font-face embedding, use of images, or the Infinite Scroll plugin.

Here is the code called in the header section:

jQuery(window).load(function($) { 
    // We can only load masonry on window.load because of embedded swfobjects
    jQuery('.content').masonry({
        singleMode: true,
        resizable: true,
        animate: false
    }); // initiate masonry
    jQuery('.content').infinitescroll({
        navSelector: "div.navigation",
        // selector for the paged navigation (it will be hidden)
        nextSelector: "div.navigation div.nav-previous a",
        // selector for the NEXT link (to page 2)
        itemSelector: ".content div.post",
        // selector for all items you'll retrieve
        loadingText: "Lädt weitere Beiträge..."
    }, function(newElements) {
        jQuery(this).masonry({
            appendedContent: jQuery(newElements)
        });
    })
});


Try to use the "DOM ready" event, which fires after the "load" event (when images have finished loading etc.).

jQuery has a nice shortcut for that. Instead of

jQuery(window).load(function() {
  // ...
});

do

jQuery(function() {
  // ...
});

Or, simply:

$(function() {
  // ...
});

When you do not use any other JS framework in parallel, it's safe and convenient to use $ in place of jQuery.

0

精彩评论

暂无评论...
验证码 换一张
取 消