基本图像滑块(PHP Javascript)

时间:2016-09-04 00:36:53

标签: javascript jquery html css

我正在尝试使用基本图像滑块来为我的网站工作: www.gohatchmyegg.com

不幸的是,它没有用。

这是我的代码:

    .slider
    {
    width:  75%;
    height: 50%;
    top: -15%;
    margin: auto;
    position: relative;
    border: 1px solid black;
    vertical-align: top;
    display: flex;
    align-items: center;
    justify-content: center;
    }

    .slider img
    {
    position: relative;
    overflow: none;
    }
 <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>

    <script type="text/javascript">

    $(document).ready(function(){
    $(".slider #1").fadeIn(3000);
    $(".slider #1").delay(700).fadeOut(2000);
  
    var slidecount=$(".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==slidecount){
    count=1;

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

    </script>
    <div class="slider">
    <img id="1" src="http://www.gohatchmyegg.com/wp-content/themes/BLANK-Theme/images/Pokemon/001.png" />
    <img id="2" src="http://www.gohatchmyegg.com/wp-content/themes/BLANK-Theme/images/Pokemon/002.png" />
    <img id="3" src="http://www.gohatchmyegg.com/wp-content/themes/BLANK-Theme/images/Pokemon/003.png" />
    <img id="4" src="http://www.gohatchmyegg.com/wp-content/themes/BLANK-Theme/images/Pokemon/004.png" />
    <img id="5" src="http://www.gohatchmyegg.com/wp-content/themes/BLANK-Theme/images/Pokemon/005.png" />
    </div>

最初的问题是图像一次显示全部。

我需要图像滑块一次显示1张图像,并一次滑动1张图像

我浏览了代码,我找到了解决方法。

但是现在,图像滑块显示1张图像(一次),它一次滑动1张图像,但它会卡在第二张图像上。

我需要图像滑块随机循环显示图像。

2 个答案:

答案 0 :(得分:0)

您没有正确关闭文档就绪标记 - 缩进的好处是您可以清楚地看到它:

$(document).ready(function(){
    $(".slider #1").fadeIn(3000);
    $(".slider #1").delay(700).fadeOut(2000);

    var slidecount=$(".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==slidecount){
              count=1;
           }else{
              count=count + 1;
           }
       },6500);
 })

答案 1 :(得分:0)

没关系我让它工作

这是jsfiddle

http://jsfiddle.net/rAqcP/250/

DIV CODE

<div class="slider">
<img id="1" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/001.png" />
<img id="2" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/002.png" />
<img id="3" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/003.png" />
<img id="4" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/004.png" />
<img id="5" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/005.png" />
<img id="6" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/006.png" />
<img id="7" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/007.png" />
<img id="8" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/008.png" />
<img id="9" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/009.png" />
<img id="10" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/010.png" />
<img id="11" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/011.png" />
<img id="12" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/012.png" />
<img id="13" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/013.png" />
<img id="14" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/014.png" />
<img id="15" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/015.png" />
<img id="16" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/016.png" />
<img id="17" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/017.png" />
<img id="18" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/018.png" />
<img id="19" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/019.png" />
<img id="20" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/020.png" />
<img id="21" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/021.png" />
<img id="22" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/022.png" />
<img id="23" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/023.png" />
<img id="24" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/024.png" />
<img id="25" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/025.png" />
<img id="26" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/026.png" />
<img id="27" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/027.png" />
<img id="28" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/028.png" />
<img id="29" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/029.png" />
<img id="30" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/030.png" />
<img id="31" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/031.png" />
<img id="32" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/032.png" />
<img id="33" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/033.png" />
<img id="34" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/034.png" />
<img id="35" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/035.png" />
<img id="36" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/036.png" />
<img id="37" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/037.png" />
<img id="38" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/038.png" />
<img id="39" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/039.png" />
<img id="40" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/040.png" />
<img id="41" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/041.png" />
<img id="42" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/042.png" />
<img id="43" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/043.png" />
<img id="44" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/044.png" />
<img id="45" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/045.png" />
<img id="46" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/046.png" />
<img id="47" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/047.png" />
<img id="48" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/048.png" />
<img id="49" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/049.png" />
<img id="50" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/050.png" />
<img id="61" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/061.png" />
<img id="62" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/062.png" />
<img id="63" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/063.png" />
<img id="64" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/064.png" />
<img id="65" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/065.png" />
<img id="66" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/066.png" />
<img id="67" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/067.png" />
<img id="68" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/068.png" />
<img id="69" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/069.png" />
<img id="70" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/070.png" />
<img id="71" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/071.png" />
<img id="72" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/072.png" />
<img id="73" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/073.png" />
<img id="74" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/074.png" />
<img id="75" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/075.png" />
<img id="76" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/076.png" />
<img id="77" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/077.png" />
<img id="78" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/078.png" />
<img id="79" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/079.png" />
<img id="80" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/080.png" />
<img id="81" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/081.png" />
<img id="82" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/082.png" />
<img id="83" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/083.png" />
<img id="84" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/084.png" />
<img id="85" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/085.png" />
<img id="86" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/086.png" />
<img id="87" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/087.png" />
<img id="88" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/088.png" />
<img id="89" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/089.png" />
<img id="90" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/090.png" />
<img id="91" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/091.png" />
<img id="92" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/092.png" />
<img id="93" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/093.png" />
<img id="94" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/094.png" />
<img id="95" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/095.png" />
<img id="96" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/096.png" />
<img id="97" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/097.png" />
<img id="98" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/098.png" />
<img id="99" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/099.png" />
<img id="100" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/Pokemon/100.png" />
<img id="101" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/101.png" />
<img id="102" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/102.png" />
<img id="103" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/103.png" />
<img id="104" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/104.png" />
<img id="105" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/105.png" />
<img id="106" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/106.png" />
<img id="107" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/107.png" />
<img id="108" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/108.png" />
<img id="109" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/109.png" />
<img id="110" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/110.png" />
<img id="111" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/111.png" />
<img id="112" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/112.png" />
<img id="113" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/113.png" />
<img id="114" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/114.png" />
<img id="115" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/115.png" />
<img id="116" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/116.png" />
<img id="117" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/117.png" />
<img id="118" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/118.png" />
<img id="119" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/119.png" />
<img id="120" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/120.png" />
<img id="121" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/121.png" />
<img id="122" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/122.png" />
<img id="123" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/123.png" />
<img id="124" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/124.png" />
<img id="125" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/125.png" />
<img id="126" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/126.png" />
<img id="127" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/127.png" />
<img id="128" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/128.png" />
<img id="129" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/129.png" />
<img id="130" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/130.png" />
<img id="131" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/131.png" />
<img id="132" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/132.png" />
<img id="133" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/133.png" />
<img id="134" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/134.png" />
<img id="135" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/135.png" />
<img id="136" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/136.png" />
<img id="137" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/137.png" />
<img id="138" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/138.png" />
<img id="139" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/139.png" />
<img id="140" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/140.png" />
<img id="141" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/141.png" />
<img id="142" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/142.png" />
<img id="143" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/143.png" />
<img id="144" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/144.png" />
<img id="145" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/145.png" />
<img id="146" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/146.png" />
<img id="147" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/147.png" />
<img id="148" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/148.png" />
<img id="149" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/149.png" />
<img id="150" src="http://www.gohatchmyegg.com/wp-content/themes/GoHatchMyEgg/images/pokemon/150.png" />
</div>

JAVASCRIPT CODE

<script type="text/javascript"> 
$(document).ready(function() {

//$('.slider #1').show({right:'0'}, 500);
$('.slider #1').show('slide',{direction:'right'},500);
$('.slider #1').delay(5500).hide('slide',{direction:'left'},500);

var sliderTotalImg = $('.slider img').size();    
var counterIndex = 2;
var slidecount=150;

setInterval(function () {

    //$('.slider #' + counterIndex).show({right:'0'}, 500);
    $('.slider #' + counterIndex).show('slide',{direction:'right'},500);
    $('.slider #' + counterIndex).delay(5500).hide('slide',{direction:'left'},500);

    if(counterIndex==slidecount){
counterIndex=1;

}else{
counterIndex++;
}
},6500);});</script>

CSS代码

.slider {
width: 20%;
height: 30%;
overflow:hidden;
border: 1px solid black;
background-image:url("http://test.softvex.com/Slider/Img/loading.gif");
background-repeat:no-repeat;
background-position:center;
}

.slider img {
display:none;
}