我做了一个jquery幻灯片放映,但不能正常工作,我该怎么办 [英] I made a jquery slide show but it doesn't work right, what do i do

查看:61
本文介绍了我做了一个jquery幻灯片放映,但不能正常工作,我该怎么办的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我通过youtube上的视频系列制作了这个jquery滑块,它似乎无法正常工作...图像先消失,然后下一个图像就不出现了.我该如何解决这..由于功能已弃用,我正在使用旧版本的jquery

Okay so i made this jquery slider from a video series on youtube and it doesn't seem to be working right... The image fades in at first but then the next image doesn't come in. How can i fix this.. Im using older versions of jquery because of deprecated functions

这是HTML.

<!DOCTYPE html>
<html>
    <head>
        <title>
            Home
        </title>
        <link rel="stylesheet" type="text/css" href="style.css">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta charset="UTF-8">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js" type="text/javascript">
</script>
        <script src="jquery-ui-1.8.18.js" type="text/javascript">
</script>
        <script src="script.js" type="text/javascript">
</script>
    </head>
    <body class="body" onload="Slider()">
        <div class="container">
            <div class="bg">
                <div class="mainHeader">
                    <nav>
                        <ul>
                            <li class="last">
                                <a href="#">Contact</a>
                            </li>
                            <li>
                                <a href="#">Products</a>
                            </li>
                            <li>
                                <a href="#">About</a>
                            </li>
                            <li>
                                <a href="#" class="active">Home</a>
                            </li>
                        </ul>
                    </nav>
                </div>
                <div class="topArea">
                    <div class="topAInfo">
                        <h2>
                            Here is just a simple title
                        </h2>
                        <p>
                            This is just a little bit of dummy text. This is just a little bit of dummy text. This is just a little bit of dummy text. This is just a little bit of dummy text.
                        </p>
                    </div>
                </div>
                <div class="middleArea">
                    <div class="slider">
                        <img id="1" src="slide1.jpg" border="0" alt="slide1" width="800px" height="350px">
                        <img id="2" src="slide2.jpg" border="0" alt="slide2" width="800px" height="350px"> 
                        <img id="3" src="slide3.jpg" border="0" alt="slide3" width="800px" height="350px">
                    </div>
                    <div class="middleAInfo">
                        <h3>
                            Welcome to
                        </h3>
                        <p>
                            A dummy website!!
                        </p>
                    </div>
                    <div class="latestNews">
                        <hr>
                        <h2>
                            Latest News
                        </h2>
                        <div class="post">
                            <p class="date">
                                March 28, 2015
                            </p>
                            <p>
                                New advanced update with double speed and a whole bunch of cool new st.. <a href="#">more&gt;&gt;</a>
                            </p>
                        </div>
                        <div class="post">
                            <p class="date">
                                March 28, 2015
                            </p>
                            <p>
                                New advanced update with double speed and a whole bunch of cool new st.. <a href="#">more&gt;&gt;</a>
                            </p>
                        </div>
                        <div class="newsLetter">
                            <div class="newsLInfo">
                                <h3>
                                    Newsletter sign-up
                                </h3>
                                <hr>
                                <p>
                                    If you would like to sign up for our free NewsLetter please enter your email below
                                </p><a href="#">Unsubscribe</a>
                            </div><input type="text" name="textBox" class="textBox" style="width:200px; height:20px;">
                            <div class="button1">
                                Submit
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>

css:

*{margin:0;padding:0;}
@font-face {
    font-family: SketchFont;
    src: url(Fonts/Sketch_Block.ttf);
}
body{
    background:#ebebeb;
    width:80%;
    height:1300px;
}
.container{
    width:100%;
}
.mainHeader nav{
    width:95%;
    height:40px;
    position:relative;
    left:30px;
    top:60px;
    background: -webkit-linear-gradient(rgba(90, 215, 240, 0.75),rgb(33, 171, 198)); /* For Safari 5.1 to 6.0 */
    background: -o-linear-gradient(rgba(90, 215, 240, 0.75),rgb(33, 171, 198)); /* For Opera 11.1 to 12.0 */
    background: -moz-linear-gradient(rgba(90, 215, 240, 0.75),rgb(33, 171, 198)); /* For Firefox 3.6 to 15 */
    background: linear-gradient(rgba(90, 215, 240, 0.75),rgb(33, 171, 198)); /* Standard syntax */
    /*margin: 100px 50px 0 150px;*/
}
.mainHeader nav ul{

}
.mainHeader nav ul li{
    float:right;
    display:inline;
    text-align:center;
    border:1px solid #ADADA8;
    border-bottom:none;
    border-top:none;
    border-left:none;
    padding-top:20px;
}
.mainHeader nav ul li.last{
    border-right:none;
}
.mainHeader nav ul li a{
    text-decoration:none;
    /*margin:10px Use to replace paddings right/left but causes hovedr errors*/
    font-family:Arial;
    position:relative;
    top:-10px;
    color:white;
    padding:10px;
    padding-right:20px;
    padding-left:20px;
}
.mainHeader nav ul li a.active{
    background:white;
    color:black;
}
.mainHeader nav ul li a:hover{
    background:white;
    color:black;
}
.topArea{
    width:95%;
    height:300px;
    position:relative;
    left:30px;
    top:10px;
    /*margin: -50px 50px 0 150px;*/
    background: -webkit-linear-gradient(white,rgb(33, 171, 198)); /* For Safari 5.1 to 6.0 */
    background: -o-linear-gradient(white,rgb(33, 171, 198)); /* For Opera 11.1 to 12.0 */
    background: -moz-linear-gradient(white,rgb(33, 171, 198)); /* For Firefox 3.6 to 15 */
    background: linear-gradient(white,rgb(33, 171, 198)); /* Standard syntax */
}
.topArea .topAInfo{
    margin:20px;
    padding-top:60px;
    width:60%;
    margin:50px;
    font-family:;
}
.topArea .topAInfo h2{
    font-family:SketchFont;
    font-weight: normal;
}
.topArea .topAInfo p{
    line-height:25px;
    font-family:cursive;
    font-size:15px;
}
.bg{
    width:100%;
    height:1200px;
    position:relative;
    left:10%;
    background:linear-gradient(blue, white, white, blue); /* Standard syntax */
    /*background-image:url(bg2.jpg);*/
    background-repeat: no-repeat;
}
.middleArea{
    background:linear-gradient(white, white, #55C4E9); /* Standard syntax */;
    height:600px;
    width:95%;
    position:relative;
    left:30px;
    top:10px;
}
.middleArea .middleAInfo {
    padding:30px 0 0 30px;
}
.middleArea .middleAInfo p{
    color:#49CBF0;
    font-size:30px;
    font-weight:400;
}
.middleArea .latestNews {
    width:250px;
    height:300px;
    background:#0099cc;
    float:right;
    position:relative;
    top:-60px;
    border:1px solid #D6D8D8;
}
.middleArea .latestNews hr{
    position:relative;
    top:50px;
    color:black;
    width:90%;
    margin-left:10px;
}
.middleArea .latestNews h2{
    padding:10px 10px 10px 10px;
    color:white;
}
.middleArea .latestNews p.date{
    color:white;
    font-size:13px;
    font-weight:bold;
    padding:10px 10px 10px 20px;
}
.middleArea .latestNews p{
    color:white;
    font-size:13px;
    position:relative;
    left:10px;
    width:225px;
}
.middleArea .latestNews a{
    color:blue;
    font-size:15px;
    font-family:Arial;
}
.middleArea .latestNews .newsLetter{
    background:white;
    width:250px;
    height:200px;
    position:relative;
    top:80px;
    border:1px solid #D6D8D8;
}
.middleArea .latestNews .newsLetter .textBox{
    position:relative;
    top:40px;
    left:25px;
}
.middleArea .latestNews .newsLetter .button1{
    width:50px;
    height:25px;
    background:#1768ED;
    padding:3px 10px 2px 10px;
    border-radius:7px;
    text-align:center;
    color:white;
    font-family:Arial;
    position:relative;
    top:45px;
    left:155px;
}
.middleArea .latestNews .newsLetter .button1:hover{
    cursor: pointer;
}
.middleArea .latestNews .newsLetter h3{
    position:relative;
    top:15px;
    left:10px;
    color:#21AFEA;
}
.middleArea .latestNews .newsLetter hr{
    position:relative;
    top:20px;
    color:#21AFEA;
}
.middleArea .latestNews .newsLetter p{
    color:black;
    position:relative;
    top:40px;
    color:#21AFEA;
    font-size:15px;
}
.middleArea .latestNews .newsLetter a{
    position:relative;
    top:90px;
    left:30px;
}
.slider{
    width:800px;
    height:350px;
    overflow:hidden;
    margin:30px auto;
    background-image:url(loading.gif);
    background-repeat:no-repeat;
    background-position:center;
    background-size: 100px 100px;
}
.slider img{
    display:none;
}

javascript:

javascript:

    function Slider(){
        $(".slider #1").show("fade", 500);
        $(".slider #1").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);
    }

和图像zip

https://www.dropbox.com/s/z8cxqlfp7i46066/slides.zip?dl=0

推荐答案

问题是您的语法错误,类选择器应包含一个点

The problem is that your syntax is wrong, the class selector should contain a dot

$("slider")更改为$(".slider")

尝试

function Slider(){
$(".slider #1").show("fade", 500);
$(".slider #1").delay(5500).hide("slide", {direction:'left'}, 500);

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

setInterval(function(){
    console.log(count);
    $(".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);
  }

,然后将滑盖容器替换为

and replace your slider container with

       <div class="slider">
            <img id="1" src="slide1.jpg" border="0" alt="slide1" width="800px" height="350px">
            <img id="2" src="slide2.jpg" border="0" alt="slide2" width="800px" height="350px">
            <img id="3" src="slide3.jpg" border="0" alt="slide3" width="800px" height="350px">
        </div>

并确保将您的图像slider3.jpg重命名为slide3.jpg

and make sure to rename your image slider3.jpg to slide3.jpg

这篇关于我做了一个jquery幻灯片放映,但不能正常工作,我该怎么办的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆