【问题标题】:Masonry Wordpress $(window).load never loads砌体 Wordpress $(window).load 从不加载
【发布时间】:2013-01-18 01:08:42
【问题描述】:

我正在尝试将 Masonry 集成到现有的修改后的 Wordpress 网站中。我最初将脚本编写为$(document).ready,但遇到了非常常见的时序问题,导致图像重叠,因此我将其重写为$(window).load。图像现在以标准的单列布局加载,而 Masonry 永远不会加载。我尝试以各种方式编写订单,但尚未看到任何进展。我无法简单地告诉 jQuery 需要注意什么高度,因为每个图像的大小都不同。

*我确定最初的问题是时间问题,因为页面加载了重叠的图像,但是当我点击另一个页面然后返回时,砌体布局完美地重新加载。

脚本

jQuery(function($){
// Grid JS
/*
$(document).bind('keydown', 'Alt+Shift+g', function(){
$("div#container").toggleClass("grid");
});

*/
$('#linky').masonry({
singleMode: true, 
itemSelector: '.boxy' 
});

$('.boxy').hover(function() {
$(this).addClass('boxy-hover');
}, function() {
$(this).removeClass('boxy-hover');
});  
});  

HTML

<div id="linky">
<?php
  $linksPosts = new WP_Query();
  $linksPosts->query('showposts=15&cat=-7');
?>
<?php while ($linksPosts->have_posts()) : $linksPosts->the_post(); ?>
<div class="boxy">
<div class="read">
<a href="<?php if(get_post_meta($post->ID, "url", true)) echo get_post_meta($post->ID,      "url", true); else the_permalink(); ?>"><?php the_post_thumbnail(); ?></a>
<?php the_content('Read the rest of this entry &raquo;'); ?>
</div>
</div>
<?php endwhile; ?>
</div>

CSS

#linky {
width: 1008px;
height: 100%;
} 

#linky .boxy {
width: 306px;
height: auto;
padding: 0 15px 15px 0;
margin-left: 15px;
}

.read {
height: auto;
}

.read img{
max-width: 306px;
height: auto;
}

任何帮助将不胜感激, 谢谢!

【问题讨论】:

    标签: jquery wordpress jquery-masonry


    【解决方案1】:

    那么尝试使用jQuery 而不是$

    jQuery('#linky').masonry({
        singleMode: true, 
        itemSelector: '.boxy' 
    });
    

    我已经在您的 Chrome 页面上对其进行了测试,$('#linky') 给出了错误,但jQuery('#linky') 有效。好像你在某处打电话给jQuery.noConflict(),因为你也在使用jQuery(function()而不是$(function()

    【讨论】:

    • 我知道它必须是简单的东西。现在完美运行。谢谢!
    猜你喜欢
    • 2014-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多