错误图像未在jQuery幻灯片中显示

时间:2013-02-22 22:56:58

标签: javascript jquery html dreamweaver

我正在使用jQuery和HTML来制作幻灯片,但我遇到了一些麻烦:一张图片出现,其他幻灯片则没有。我无法弄清问题在哪里。有没有人遇到类似的问题?

以下是代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>JQuery Slider</title>
    <style type="text/css">
      .slider{
        width:800px;
        height:350px;
        overflow:hidden;
        margin:30px auto;
      }
      .slider img{
        width:800px;
        height:350px;
        display:none;
      }
    </style>
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/jquery-ui.min.js"></script>
<script type="text/javascript">
 function Slider(){
 $('#img1').show("fade", 500);
 $('#img2').delay(5500).hide("slide", {direction:"left"}, 500);

 var sc=$(".slider img").size();
 var count=2;

 setInterval(function(){

     $(".slider#"+count).show("slide", {direction:"right"}, 500);
     $(".slider#"+count).delay(5500).hide("slide", {direction:"left"}, 500);

     if(count == sc){

     count=1;
     }else{
        count=count+1;
     }
     }, 6500);
 }

</script>
</head>

<body onload="Slider();">

<div class="slider">

<img id="img1" src="img/13052012438.jpg"border="0"alt="image1" />
<img id="img2" src="img/25052012442.jpg"border="0"alt="image2" />

<img id="img3" src="img/13052012439.jpg"border="0"alt="image3" />
<img id="img4" src="img/25052012441.jpg"border="0"alt="image4" />

</div>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

使用此...

$(document).ready(function(){
 $('#img1').show("fade", 500);
 $('#img2').delay(500).hide("slide", {direction:"left"}, 500);
 var sc=$(".slider img").size();
 var count=2;

 setInterval(function(){
     $("#img"+count).show("slide", {direction:"right"}, 500);
     $("#img"+count).delay(500).hide("slide", {direction:"left"}, 500);
     if(count == sc){
         count=1;
     }else{
        count=count+1;
     }
     }, 6500);
 });

并查看此jSfiddle example