在使用Ajax导航并返回主页后,Nivo Slider中断了

时间:2013-02-11 16:44:06

标签: ajax jquery nivo-slider

我在使用Ajax加载其内容的网站中使用Nivo Slider。它可以避免用户在每次点击链接时加载新页面。

我的问题是,当我最初加载主页时,滑块工作正常;但如果我离开那个页面然后回到它,它只是在循环上加载gif。有人可以帮忙吗?

我的index.php就是这样:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>I.C.T - St. Patrick's Academy, Lisburn</title>
    <script type="text/javascript" src="assets/js/jqmin.js"></script>
    <link rel="stylesheet" type="text/css" href="assets/css/style.css" media="all" />
    <script type="text/javascript" src="assets/js/js.js"></script>
    <link rel="stylesheet" type="text/css" href="assets/css/nivo.css" media="all" />
    <script type="text/javascript" src="assets/js/sliderpack.js"></script>
    <script type="text/javascript" src="assets/js/slide.js"></script>
  </head>
  <body>
    <div id="wrap">
      <div id="head">
        <div id="links">
          <ul>
            <li><a href="includes/home.php" class="left">Home</a></li>
            <li><a href="includes/about.php">About</a></li>
            <li><a href="includes/contact.php">Contact</a></li>
            <li><a href="includes/learn.php" class="right">Learn</a></li>
          </ul>
        </div>
        <img src="assets/images/logo.png" alt="logo" />
      </div>
      <div id="screen">
        <div id="pad"></div>
        <div id="cont_wrap">
          <div id="cont">
            <h2>Home</h2>
            <div class="slider-wrapper">
              <div id="slider" class="nivoSlider">
                <img src="assets/images/slide1.jpg" alt="1" />
                <img src="assets/images/slide2.jpg" alt="2" />
                <img src="assets/images/slide3.jpg" alt="3" />
              </div>
            </div>
          </div>
        </div>
      </div>
      <div id="foot">
        <p align="center"><i>Copyright 2013 - Finbar Maginn - St. Patrick's Academy, Lisburn</i></p>
      </div>
    </div>
  </body>
</html>

(请注意,我的Nivo Slider初始化位于slide.js内,如下所示:)

$(window).load(function() {
  $('#slider').nivoSlider({
    effect: 'random', // Specify sets like: 'fold,fade,sliceDown'
    slices: 16, // For slice animations
    boxCols: 6, // For box animations
    boxRows: 3, // For box animations
    animSpeed: 1000, // Slide transition speed
    pauseTime: 5000, // How long each slide will show
    startSlide: 0, // Set starting Slide (0 index)
    directionNav: false, // Next & Prev navigation
    controlNav: false, // 1,2,3... navigation
    controlNavThumbs: false, // Use thumbnails for Control Nav
    pauseOnHover: false, // Stop animation while hovering
    manualAdvance: false, // Force manual transitions
    prevText: 'Prev', // Prev directionNav text
    nextText: 'Next', // Next directionNav text
    randomStart: false, // Start on a random slide
    beforeChange: function(){}, // Triggers before a slide transition
    afterChange: function(){}, // Triggers after a slide transition
    slideshowEnd: function(){}, // Triggers after all slides have been shown
    lastSlide: function(){}, // Triggers when last slide is shown
    afterLoad: function(){} // Triggers when slider has loaded
  });
});

我正在使用的Ajax jQuery文件是:

$(document).ready(function() {
  var hash = window.location.hash.substr(1);
  var href = $('#links li a').each(function(){
    var href = $(this).attr('href');
    if(hash==href.substr(0,href.length-3)){
      var toLoad = hash+'.php #cont';
      $('#cont').load(toLoad)
    }
  });
  $('#links li a').click(function(){
    var toLoad = $(this).attr('href')+' #cont';
    $('#cont').fadeOut('fast',loadContent);
    $('#load').remove();
    $('#wrap').append('<span id="load">LOADING...</span>');
    $('#load').fadeIn('fast');
    window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-4);
    function loadContent() {
      $('#cont').load(toLoad,'',showNewContent());
    }
    function showNewContent() {
      $('#cont').fadeIn('fast',hideLoader('fast'));
    }
    function hideLoader() {
      $('#load').fadeOut('fast');
    }
    return false;
  });
});

这是我的CSS:

body {
  font-size:95%;
  font-family:georgia;
  line-height:1.576;
}
h2 {
  padding:0;
  margin:0;
}
#wrap {
  margin:0 auto;
  width:784px;
}
#head {
  width:100%;
  height:175px;
}
#links {
  width:300px;
  height:30px;
  padding:140px 0 0 0;
  float:right;
  text-align:right;
}
#links ul {
  margin:0;
  padding:0;
}
#links ul li {
  display:inline;
  margin:0 -2px 0 -2px;
}
#links ul li a {
  font-size:1em;
  -webkit-transition: 0.1s;
  -moz-transition: 0.1s;
  -ms-transition: 0.1s;
  -o-transition: 0.1s;
  text-decoration:none;
  color:black;
  background:-webkit-linear-gradient(bottom, white, #74b998);
  background:-o-linear-gradient(bottom, white, #74b998);
  background:-ms-linear-gradient(bottom, white, #74b998);
  background:-moz-linear-gradient(bottom, white, #74b998);
  padding:3px 5px 3px 5px;
}
#links ul li a:hover {
  background:-webkit-linear-gradient(top, white, #74b998);
  background:-o-linear-gradient(top, white, #74b998);
  background:-ms-linear-gradient(top, white, #74b998);
  background:-moz-linear-gradient(top, white, #74b998);
  padding:7px 5px 7px 5px;
}
.left {
  border-bottom-left-radius:10px;
  -webkit-border-bottom-left-radius:10px;
  -moz-border-bottom-left-radius:10px;
  -ms-border-bottom-left-radius:10px;
  -o-border-bottom-left-radius:10px;
  border-top-left-radius:10px;
  -webkit-border-top-left-radius:10px;
  -moz-border-top-left-radius:10px;
  -ms-border-top-left-radius:10px;
  -o-border-top-left-radius:10px;
}
.right {
  border-bottom-right-radius:10px;
  -webkit-border-bottom-right-radius:10px;
  -moz-border-bottom-right-radius:10px;
  -ms-border-bottom-right-radius:10px;
  -o-border-bottom-right-radius:10px;
  border-top-right-radius:10px;
  -webkit-border-top-right-radius:10px;
  -moz-border-top-right-radius:10px;
  -ms-border-top-right-radius:10px;
  -o-border-top-right-radius:10px;
}
.radius {
  border-radius:10px;
  -webkit-border-radius:10px;
  -moz-border-radius:10px;
  -ms-border-radius:10px;
  -o-border-radius:10px;
}
#screen {
  width:100%;
  height:480px;
  background-image:url(../images/bckgrnd.png);
}
#pad {
  width:100%;
  height:29px;
}
#cont_wrap {
  overflow:auto;
  margin:0 auto;
  width:724px;
  height:335px;
  padding: 0 0 0 6px;
}
#load {
  display: none;
  position: absolute;
  top: 150px;
  left: 950px;
  text-indent: -9999em;
  width: 16px;
  height: 16px;
  background: url(../images/load.gif) no-repeat;
}
#cont {
}
#foot {
  width: 100%;
  font-size:90%;
  color:gray;
}
#slider {
  margin: 0 auto;
  width: 700px;
  height: 273px;
}
.nivoSlider {
  position: relative;
  background: url(../images/load.gif) no-repeat 50% 50%;
}
.nivoSlider img {
  position: absolute;
  top: 0px;
  left: 0px;
  display: none;
}
.nivoSlider a {
  border: 0;
  display: block;
}

0 个答案:

没有答案