2011-06-20 38 views
2

我正在使用Smooth Div Scroll jQuery Plugin在网站上移动幻灯片。加载到电影胶片中的图像是自定义发布类型,每个图像都有一个标题并包含单个图像。该插件在包含任意数量图像的长div上水平滚动。我的问题是,即使在图像消失之后,我仍然可以滚动显示无限的时间。如何在WordPress中加载帖子后运行jQuery方法?

这里是我的问题的故障:

  • 我已经使用普通图像后循环,而不是试图 ,一切 预期一样(没有无限 滚动)。
  • 我试过在document.ready和window.load之间设置脚本,使用document.ready它们根本不加载。
  • 我试过调用一个公共函数“recalculateScrollableArea”,以便可以在图像加载无效后计算该区域,然后通过在脚本中调用jQuery中的警告框,我可以看到它仍然被调用在图像加载之前。

那应该怎么看平时: How it should look usually 如何看起来,当它过卷轴: How it looks when it over-scrolls

的平滑股利滚动代码和下面的初始化代码都被称为在页脚底部:

jQuery(window).load(function() { 
    jQuery("div#makeMeScrollable").smoothDivScroll({ 
     autoScroll: "onstart" , 
     autoScrollDirection: "backandforth", 
     autoScrollStep: 1, 
     autoScrollInterval: 15, 
     visibleHotSpots: "always" 
    }); 

这就是我所做的尝试和修正调整大小:

jQuery(document).ready(function() { 
    jQuery("#makeMeScrollable").smoothDivScroll("disable"); 
}); 

我还要提到,对于职位的图像由“P”标签包围,但我不明白为什么这将是问题。

感谢您的阅读!

编辑: 下面是一些更多的代码,其中大部分是股票,当只是普通IMGS的地方,而不是循环工作。

底座CSS和jQuery文件是相同的,在这个简单的演示的那些:http://www.smoothdivscroll.com/basicDemo.htm

jQuery和jQuery UI的进口(工作)

function jQuery_from_Google() { 
    if (!is_admin()) { // actually not necessary, because the Hook only get used in the Theme 
     wp_deregister_script('jquery'); // unregistered key jQuery 
     wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js', false, '1.5.2'); // register key jQuery with URL of Google CDN 
     wp_enqueue_script('jquery'); // include jQuery 
    } 
} 
// nur for Themes since WordPress 3.0 
add_action('after_setup_theme', 'jQuery_from_Google'); // Theme active, include function 

function jQueryUI_from_Google() { 
    if (!is_admin()) { // actually not necessary, because the Hook only get used in the Theme 
     wp_register_script('jqueryui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js'); // register key jQueryUI with URL of Google CDN 
     wp_enqueue_script('jqueryui'); // include jQueryUI 
    } 
} 
// nur for Themes since WordPress 3.0 
add_action('after_setup_theme', 'jQueryUI_from_Google'); // Theme active, include function 

进口发生在页脚底部:

<?php // Smooth Div Scroll inport for filmstrip galleries ?> 
<script type="text/javascript" src="<?php bloginfo('stylesheet_directory'); ?>/javascript/filmstrip.js"></script> 
<script type="text/javascript" src="<?php bloginfo('stylesheet_directory'); ?>/SmoothDivScroll-1.1/js/jquery.smoothDivScroll-1.1-min.js"></script> 
</body> 
</html> 

这里是一个部分的代码片段,它使用的内容的循环:

<?php if(is_page('engagements')) { ?> 
<div id="makeMeScrollable"> 
    <div class="scrollingHotSpotLeft"></div> 
    <div class="scrollingHotSpotRight"></div> 
    <div class="scrollWrapper"> 
     <div class="scrollableArea"> 
      <?php 
       $args = array('post_type' => 'engagement_photos'); 
       $loop = new WP_Query($args); 
       while ($loop->have_posts()) : $loop->the_post(); 
        the_content(); 
       endwhile; 
      ?> 
     </div> 
    </div> 
</div> 
<?php } else if(is_page('weddings')) { ?> 

这里是WordPress中添加图像的例子: enter image description here

+1

所有浏览器?链接到您的网页? – Sparky

+0

我现在正在本地主机服务器上开发,所以它仍然不在线。所有浏览器都出现这个问题。 – mitchellbutler

+0

如果您发布了所有相关的代码,那么可能会有所帮助......但是到目前为止发布的内容可以完成很多故障排除工作。 – Sparky

回答

0

发现了问题,我试图把常规硬编码IMGS它工作得很好,并然后用“p”标签将它们包裹起来,从而产生相同的问题。我想我只是在过度思考这个问题。抱歉。现在想出如何让循环产生imgs。

+0

也修正了这一点,它只需要一个<?php remove_filter('the_content','wpautop'); ?>在模板的顶部。感谢大家。 – mitchellbutler

1

你可能想尝试以下代码在functions.php文件中。

function init_my_scripts() 
{ 
    if (!is_admin()) 
    { 
     wp_deregister_script('jquery'); 
     wp_register_script('jquery', 'http://code.jquery.com/jquery-1.6.1.min.js'); 
     wp_enqueue_script('jquery'); 

     wp_deregister_script('jQuery UI Core'); 
     wp_register_script('jQuery UI Core', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js'); // register key jQueryUI with URL of Google CDN 
     wp_enqueue_script('jQuery UI Core'); // include jQueryUI 

     wp_register_script('filmstrip', get_bloginfo('template_directory').'/javascript/filmstrip.js'); 
     wp_enqueue_script('filmstrip'); 

     wp_register_script('smoothDivScroll', get_bloginfo('template_directory').'/SmoothDivScroll-1.1/js/jquery.smoothDivScroll-1.1-min.js'); 
     wp_enqueue_script('smoothDivScroll'); 

    } 
} 

add_action('init', 'init_my_scripts'); 

当然,你可以改变jQuery的CDN到谷歌CDN,变“template_directory”到“stylesheet_directory”等

+0

我刚试过,但我仍然有同样的问题。谢谢。 – mitchellbutler

+0

我找到了我的问题的答案,但仅供将来参考,这段代码究竟做了什么?我应该总是在函数文件中注册jQuery插件吗? – mitchellbutler

+1

这是最佳做法。您可能需要检查wp_enqueue_script函数的资源部分中列出的链接。 http://codex.wordpress.org/Function_Reference/wp_enqueue_script – Box

相关问题