Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
171 views
in Technique[技术] by (71.8m points)

Jquery slideshow not working in Joomla3 template

I recreate the jquery slideshow by Jon Raasch mentioned on his blog

http://jonraasch.com/blog/a-simple-jquery-slideshow

this works like a charm in a normal project setup, however if i try to imply it in a joomla template, i can't seem to address the DOM elements within the setInterval function. it returns the active variable as null.

here's the template code: http://cl.ly/1m2o3U1O3p3J

the html part:

<body>
        <div id="slideShow">
                    <img src="<?php echo $this->baseurl; ?>/templates/mushi/images/img1.jpg" alt="" title="" class="active" />
                    <img src="<?php echo $this->baseurl; ?>/templates/mushi/images/img2.jpg" alt="" title="" />
                    <img src="<?php echo $this->baseurl; ?>/templates/mushi/images/img3.jpg" alt="" title="" />
        </div>
</body>

the javascript part:

function slideSwitch() {

    var $active = $('#slideShow .active');
        console.log($('#slideShow img:last'));

        if ( $active.length == 0 ) $active = $('#slideShow img:last');

        var $next =  $active.next().length ? $active.next()
            : $('#slideShow img:first');
            console.log("here");
        $active.addClass('last-active');

        $next.css({opacity: 0.0})
            .addClass('active')
            .animate({opacity: 1.0}, 1000, function() {
                $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval("slideSwitch()", 5000);
});

any help would be much apreciated thx

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Ok i solved the problem, there was a conflict with the jquery. I replaced '$' with 'jQuery' and it now works fine.

jQuery(function() {
    setInterval(function(){
        var $active = jQuery('#slideShow img.active');

        if ( $active.length == 0 ) $active = jQuery('#slideShow img:last');

        var $next =  $active.next().length ? $active.next()
            : jQuery('#slideShow img:first');
            console.log("here");
        $active.addClass('last-active');

        $next.css({opacity: 0.0})
            .addClass('active')
            .animate({opacity: 1.0}, 1000, function() {
                $active.removeClass('active last-active');
            });
    }, 5000);
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...