Search code examples
jquerycycle

Using cycle to change a banner image AND a background image at the same time


I have an installation of Cycle by Malsup working fine on my #banner div but i want it to change the background of the #banner-container div at the same time. Basically #banner-container has a very blurred version of the images in the #banner div but i want them to change at the same time. Any idea on how i can do this?

jQuery:

$('#banner') 
    .cycle({ 
    fx: 'fade', 
    speed: '1000', 
    timeout: '8000', 
    pager: '#pager',
    next: '#next',
    prev: '#prev',
    cleartypeNoBg: 'true'
});

HTML:

<section id="banner-container">
            <div id="banner-holder">
                <a href="#">
                    <div id="cta">
                        <p class="arrange">Arrange a visit</p>
                        <p class="info">If you’d like to come and see the school, click to arrange a visit!</p>
                    </div>
                </a>
                <div id="banner">
                    <img src="template/banner-1.png" alt="">
                    <img src="template/banner-1.png" alt="">
                    <img src="template/banner-1.png" alt="">
                    <img src="template/banner-1.png" alt="">
                    <img src="template/banner-1.png" alt="">
                </div>
                <div id="controls">
                    <div id="prev"></div>
                    <div id="next"></div>
                </div>
            </div>
            <div id="pager"></div>
        </section>

Solution

  • $('#banner') 
        .cycle({ 
        fx: 'scrollVert', 
        speed: '1000', 
        timeout: '8000', 
        pager: '#pager',
        pagerAnchorBuilder: function(i) {
            return '<a href="#"></a>';
        },
        next: '#next',
        prev: '#prev',
        cleartypeNoBg: 'true'
    });
    
    $('#blurred-background')
        .cycle({ 
        fx: 'fade', 
        speed: '1000', 
        timeout: '8000',
        next: '#next',
        prev: '#prev',
        pager: '#pager',
        pagerAnchorBuilder: function(i) {
            return $('#pager a:eq('+i+')');
        },
        cleartypeNoBg: 'true',
    });