【问题标题】:move images in a line with timed effect以定时效果移动图像
【发布时间】:2015-08-14 16:48:13
【问题描述】:

我的想法是我有一个带有一些图像的 div(在水平线上),您只能看到 div 中的第一张图像。 目前有5张图片。 我想将图像从右向左移动,离开 div(和屏幕),在最后一张图像移动后,第一张图像将在前面(即 1 个整个循环) 要开始动画,请单击一个按钮。

现在的诀窍是,在每个奇数编号的图像上,动画都必须停止片刻。所以起始图像是 1,然后通过数字 2 并在 3 处停止几秒钟,然后通过数字 4 并在数字 5 处停止,之后图像再次继续到第一个并停止,直到再次单击开始按钮。

我希望能够相当容易地扩展图像数量。

到目前为止,我在 CSS / HTMl 中所拥有的是

<body>

<div id="container">


    <div id="fotos">
        <div class="image"><img src="afb_stuk/1.png"/></div>
        <div class="image"><img src="afb_stuk/2.png"/></div>
        <div class="image"><img src="afb_stuk/3.png"/></div>

        <div style="clear:both"></div>
    </div>



</div>
<div id="start">
    <h2 class="text"></h2>
</div>
</body>

和css

body{
padding:0px;
margin:0px;
background-image:url(afb_stuk/background.jpg);
background-repeat:no-repeat;
background-size:cover;}


#container{
position:relative;
margin-left:50px;
margin-top:25px;
height:600px;
width:1250px;
border:solid thin red;
z-index:1;
/*overflow:hidden;*/}


#fotos{
position:relative;
height:80%;
width:12000px;}


.image{
height:600px;
width:1250px;
float: left;


.image img{
height:600px;
width:auto;}


#start{
position:relative;
margin:auto;
margin-top:-10px;
height:10px;
width:60px;

border-radius: 25px;
border: 2px solid #8AC007;
padding: 20px; }



.text{
margin-top:-10px;}

【问题讨论】:

  • 你有你的代码的 jsfiddle 包括你当前的 jquery 吗?
  • 不,我没有,我还没有任何 Jquery 代码。尝试了一些东西,但仍在学习它是如何工作的,并且遇到了很多问题:(

标签: jquery css image jquery-animate move


【解决方案1】:
    <html>
    <head>
    <script>
    function start()
    {
    var y=1;
    var x=document.getElementById("image");
    setInterval(function(){check();},1000);
    function check()
    {
        if(y%2!=0)
            {
                setTimeout(function(){},3000);
            }
            x.src=''+(y%6)+'.jpg'+'';
        y++;
            if(y==6)
            start();
        }
    }
    </script>
    <style>
    body{
    padding:0px;
    margin:0px;
    background-image:url(afb_stuk/background.jpg);
    background-repeat:no-repeat;
    background-size:cover;}


    #container{
    position:relative;
    margin-left:50px;
    margin-top:25px;
    height:600px;
    width:1250px;
    border:solid thin red;
    z-index:1;
    /*overflow:hidden;*/}


    #fotos{
    position:relative;
    height:80%;
    width:12000px;}


    .image{
    height:600px;
    width:1250px;
    float: left;
    }

    .image img{
    height:600px;
    width:auto;}
    </style>
    </head>
    <body>

    <div id="container">
        <div id="fotos">
            <div class="image">
                <img src="1.jpg" id="image"/>
            </div>
        </div>
    </div>
    <button onclick="start()" id="new">Click to start!</button> 
    </div>
    </body>
    </html>

您的图片名称应采用 1、2、3、4.jpg 等格式。 并尝试累积图像之间的延迟。

【讨论】:

  • 谢谢。虽然它还没有工作,但是当我得到它的工作编辑时会发布:必须将每个图像放在他自己的 div 类框中然后它可以工作,但它还没有滑动
【解决方案2】:

我找到了一个非常好的 youtube 教程,包括一个小提琴。 我只是更改了一些效果(和图像宽度)以赋予它我喜欢和想要的效果。 感谢所有帮助过我的人 :) [1]http://jsfiddle.net/EjZzs/15/

$(function() {

//settings for slider
var width = 720;
var animationSpeed = 1000;
var pause = 3000;
var currentSlide = 1;

//cache DOM elements
var $slider = $('#slider');
var $slideContainer = $('.slides', $slider);
var $slides = $('.slide', $slider);

var interval;

function startSlider() {
    interval = setInterval(function() {
        $slideContainer.animate({'margin-left': '-='+width}, animationSpeed, function() {
            if (++currentSlide === $slides.length) {
                currentSlide = 1;
                $slideContainer.css('margin-left', 0);
            }
        });
    }, pause);
}
function pauseSlider() {
    clearInterval(interval);
}

$slideContainer
    .on('mouseenter', pauseSlider)
    .on('mouseleave', startSlider);

startSlider();

});

[2]https://youtu.be/KkzVFB3Ba_o

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-22
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 2016-10-23
    • 1970-01-01
    • 2019-10-28
    相关资源
    最近更新 更多