Jquery滑块不响应


Jquery slider not responsive - Wordpress

我正在整理一个响应式WordPress网站,但似乎在滑块方面被卡住了。我认为这是与我的网站上的东西冲突,因为默认的主题(http://wordpress.org/themes/intuition)有一个响应滑块。

这是我使用的脚本:

//SLIDESHOW
jQuery(document).ready(function(){
//HOMEPAGE SLIDES
jQuery('.slider-slides').cycle({
    speed: 1000,
    timeout: 4000,
    fx: 'scrollHorz',
    next: '.slider-next', 
    prev: '.slider-prev',
    pager: '.slider-pages',
    pause: true,
    pauseOnPagerHover: true,
    containerResize: false,
    slideResize: false,
    fit: 1
}); 
jQuery('.slider-prev, .slider-next').click(function(){
    jQuery('.slider-slides').cycle('pause');
});
    jQuery(window).scroll(function(){
    if(jQuery(document).scrollTop() > 500)
        jQuery('#toplink').addClass('active');
    else
        jQuery('#toplink').removeClass('active');
});
}); 
function slide_resize(curr, next, opts, fwd) {
var ht = jQuery(this).height();
jQuery(this).parent().animate({height: ht}); 
}

我试着将resize选项更改为true,但没有任何改变。我尝试添加宽度:100%和高度:450px的代码,建议在其他地方,但这并没有改变任何东西。

我真的是束手无策了!如果有人有什么建议,那就太好了。谢谢你!

这是我的header.php:

<?php if(cpotheme_get_option('cpo_slider_always') == 1 || is_front_page()){ ?>
        <?php $feature_args = array(
        'post_type' => array('post', 'page'),
        'meta_key' => 'page_featured',
        'meta_value' => 'slider',
        'posts_per_page' => -1,
        'orderby' => 'menu_order',
        'ignore_sticky_posts' => 1,
        'order' => 'ASC'); ?>
        <?php $slider_posts = new WP_Query($feature_args); ?>
        <?php if($slider_posts->post_count > 0): $slide_count = 0; ?>
        <div id="slider" class="slider">
            <ul class="slider-slides">
                <?php while($slider_posts->have_posts()): $slider_posts->the_post(); ?>
                <?php $slide_count++; ?>
                <?php $image_url = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), array(1500, 7000), false, ''); ?>
                <?php $slide_position = get_post_meta(get_the_ID(), 'slide_position', true); ?>
                <li id="slide_<?php echo $slide_count; ?>" class="slide slide-<?php echo $slide_position; ?>" style="background:url(<?php echo $image_url[0]; ?>) no-repeat center; background-size:cover;">
                    <div class="container">
                        <a class="slide-textbox" href="<?php the_permalink(); ?>">
                            <h2 class="slide-title"><?php the_title(); ?></h2>
                            <div class="slide-content"><?php the_excerpt(); ?></div>
                        </a>
                    </div>
                </li>
                <?php endwhile; ?>
            </ul>
            <?php if($slider_posts->post_count > 1): ?>
            <div class='slider-prev'></div>
            <div class='slider-next'></div>
            <?php endif; ?>
        </div>  
        <?php endif; ?>

        <?php }else{ ?>
        <?php $header_image = get_header_image(); if($header_image != ''): ?>
        <img src="<?php echo $header_image; ?>" class="header-image" />
        <?php endif; ?>

您似乎没有将slide_resize绑定到任何东西上。该函数存在,但在任何地方都没有调用。如果碰巧在其他地方调用了它,但没有显示:

"slider"本身和"slides"本身会收缩以响应移动(至少宽度)。你只需要考虑滑块的高度,而不是图像本身。类似这样的代码应该可以达到这个目的(抱歉有语法错误):

jQuery(window).on('resize', function(){
    var currentWidth = jQuery('.slider-slides .container').width();
    var newHeight = currentWidth / 2.444; //2.444 is your 1100/450 from the full size slider
    ('.slider-slides .container').height(newHeight); //Container height
    jQuery('.slider-slides .slide').height(newHeight); // Slide wrap's height
});