切换标签jquery / php时重新加载内容

时间:2013-10-31 19:05:38

标签: javascript php jquery pageload

我正在尝试将照片库here分为两部分。

开发人员在他的网站上发布了下面的建议,但我无法弄清楚我应该如何整合该代码:

“自定义历史插件调用的pageload(hash)方法:确定使用某些jQuery技巧调用哪一组拇指:

var thumbContainerId = $('div.navigation 
a.thumb').eq(+hash).parents('div.navigation').attr('id');
    Hide all "thumbnail containers" except the one in context (determined by the 
previous step)
    Call $.galleriffic.goto(hash);

以下是js中我必须整合变化的地方。

function pageload(hash) {
                    // alert("pageload: " + hash);
                    // hash doesn't contain the first # character.


                    if(hash) {
                        $.galleriffic.gotoImage(hash);
                    } else {
                        gallery.gotoIndex(0);
                    }
                }

这是html:

<div id="page">
    <div class="navigation-container">
        <div id="thumbs1" class="navigation">
            <ul class="thumbs noscript">
               <li>
                          <img src="/images/pct_romania/001.jpg"/>
               </li>

            </ul>
        </div>
        <div id="thumbs2" class="navigation">
            <ul class="thumbs noscript">
               <li>
                          <img src="/images/pct_hungary/001.jpg"/>
               </li>

            </ul>
        </div>
    </div>
</div>

这是完整的js:

<script type="text/javascript">
            jQuery(document).ready(function($) {
                // We only want these styles applied when javascript is enabled
                $('div.content').css('display', 'block');

                // Initially set opacity on thumbs and add
                // additional styling for hover effect on thumbs
                var onMouseOutOpacity = 0.67;
                $('#thumbs1 ul.thumbs li, div.navigation a.pageLink').opacityrollover({
                    mouseOutOpacity:   onMouseOutOpacity,
                    mouseOverOpacity:  1.0,
                    fadeSpeed:         'fast',
                    exemptionSelector: '.selected'
                });


                // Initialize Advanced Galleriffic Gallery
                var gallery = $('#thumbs1').galleriffic({
                    delay:                     2500,
                    numThumbs:                 10,
                    preloadAhead:              10,
                    enableTopPager:            false,
                    enableBottomPager:         false,
                    imageContainerSel:         '#slideshow',
                    controlsContainerSel:      '#controls',
                    captionContainerSel:       '#caption',
                    loadingContainerSel:       '#loading',
                    renderSSControls:          true,
                    renderNavControls:         true,
                    playLinkText:              'Play Slideshow',
                    pauseLinkText:             'Pause Slideshow',
                    prevLinkText:              '&lsaquo; Previous Photo',
                    nextLinkText:              'Next Photo &rsaquo;',
                    nextPageLinkText:          'Next &rsaquo;',
                    prevPageLinkText:          '&lsaquo; Prev',
                    enableHistory:             true,
                    autoStart:                 false,
                    syncTransitions:           true,
                    defaultTransitionDuration: 900,
                    onSlideChange:             function(prevIndex, nextIndex) {
                        // 'this' refers to the gallery, which is an extension of $('#thumbs')
                        this.find('ul.thumbs').children()
                            .eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
                            .eq(nextIndex).fadeTo('fast', 1.0);

                        // Update the photo index display
                        this.$captionContainer.find('div.photo-index')
                            .html(''+ (nextIndex+1) +' / '+ this.data.length);
                    },
                    onPageTransitionOut:       function(callback) {
                        this.fadeTo('fast', 0.0, callback);
                    },
                    onPageTransitionIn:        function() {
                        var prevPageLink = this.find('a.prev').css('visibility', 'hidden');
                        var nextPageLink = this.find('a.next').css('visibility', 'hidden');

                        // Show appropriate next / prev page links
                        if (this.displayedPage > 0)
                            prevPageLink.css('visibility', 'visible');

                        var lastPage = this.getNumPages() - 1;
                        if (this.displayedPage < lastPage)
                            nextPageLink.css('visibility', 'visible');

                        this.fadeTo('fast', 1.0);
                    }
                });


                /**************** Event handlers for custom next / prev page links **********************/

                gallery.find('a.prev').click(function(e) {
                    gallery.previousPage();
                    e.preventDefault();
                });

                gallery.find('a.next').click(function(e) {
                    gallery.nextPage();
                    e.preventDefault();
                });

                /****************************************************************************************/

                /**** Functions to support integration of galleriffic with the jquery.history plugin ****/

                // PageLoad function
                // This function is called when:
                // 1. after calling $.historyInit();
                // 2. after calling $.historyLoad();
                // 3. after pushing "Go Back" button of a browser
                function pageload(hash) {
                    // alert("pageload: " + hash);
                    // hash doesn't contain the first # character.


                    if(hash) {
                        $.galleriffic.gotoImage(hash);
                    } else {
                        gallery.gotoIndex(0);
                    }
                }

                // Initialize history plugin.
                // The callback is called at once by present location.hash. 
                $.historyInit(pageload, "advanced.html");

                // set onlick event for buttons using the jQuery 1.3 live method
                $("a[rel='history']").live('click', function(e) {
                    if (e.button != 0) return true;

                    var hash = this.href;
                    hash = hash.replace(/^.*#/, '');

                    // moves to a new page. 
                    // pageload is called at once. 
                    // hash don't contain "#", "?"
                    $.historyLoad(hash);

                    return false;
                });

                /****************************************************************************************/
            });
        </script>

2 个答案:

答案 0 :(得分:1)

第二个图库的所有内容都以html格式显示。

它们是隐藏的,因为没有样式和Javascript应用于它来添加Gallery效果,因为它是为第一个画廊完成的。

您需要在Javascript spinet中添加以下代码

// Initialize Advanced Galleriffic Gallery
                 var gallery2 = $('#thumbs2').galleriffic({
                    delay: 2500,
                    numThumbs: 10,
                    preloadAhead: 10,
                    enableTopPager: false,
                    enableBottomPager: false,
                    imageContainerSel: '#slideshow',
                    controlsContainerSel: '#controls',
                    captionContainerSel: '#caption',
                    loadingContainerSel: '#loading',
                    renderSSControls: true,
                    renderNavControls: true,
                    playLinkText: 'Play Slideshow',
                    pauseLinkText: 'Pause Slideshow',
                    prevLinkText: '&lsaquo; Previous Photo',
                    nextLinkText: 'Next Photo &rsaquo;',
                    nextPageLinkText: 'Next &rsaquo;',
                    prevPageLinkText: '&lsaquo; Prev',
                    enableHistory: true,
                    autoStart: false,
                    syncTransitions: true,
                    defaultTransitionDuration: 900,
                    onSlideChange: function(prevIndex, nextIndex) {
                        // 'this' refers to the gallery, which is an extension of $('#thumbs')
                        this.find('ul.thumbs').children()
                                .eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
                                .eq(nextIndex).fadeTo('fast', 1.0);

                        // Update the photo index display
                        this.$captionContainer.find('div.photo-index')
                                .html('' + (nextIndex + 1) + ' / ' + this.data.length);
                    },
                    onPageTransitionOut: function(callback) {
                        this.fadeTo('fast', 0.0, callback);
                    },
                    onPageTransitionIn: function() {
                        var prevPageLink = this.find('a.prev').css('visibility', 'hidden');
                        var nextPageLink = this.find('a.next').css('visibility', 'hidden');

                        // Show appropriate next / prev page links
                        if (this.displayedPage > 0)
                            prevPageLink.css('visibility', 'visible');

                        var lastPage = this.getNumPages() - 1;
                        if (this.displayedPage < lastPage)
                            nextPageLink.css('visibility', 'visible');

                        this.fadeTo('fast', 1.0);
                    }
                });







                /**************** Event handlers for custom next / prev page links **********************/

                gallery2.find('a.prev').click(function(e) {
                    gallery2.previousPage();
                    e.preventDefault();
                });

                gallery2.find('a.next').click(function(e) {
                    gallery2.nextPage();
                    e.preventDefault();
                });

希望它能奏效。

答案 1 :(得分:0)

你从缩略图列表中丢失了锚标记,所以这个

$("a[rel='history']").live('click', function(e) {

什么都不做。把标签放回去。

<li>
    <a class="thumb" href="#1" title="Romania 1" rel="history">
        <img src="/images/pct_romania/001.jpg"/>
    </a>
</li>