HTML5幻灯片放映效果

时间:2014-04-01 06:55:45

标签: javascript css html5

我看到一些幻灯片就像 http://slides.html5rocks.comhttp://www.htmlfivewow.com

按左或右键时,您将看到幻灯片立方体效果。 我想用这些效果制作简单的网页,只需几个div。我试图从源代码中获取css和javascript,但幻灯片无法正常工作。

  1. 动画时,div没有3D风格,只是移动和旋转。实际上http://slides.html5rocks.com在我的Firefox中没有3D效果,而在Chrome中却没有。
  2. 有没有教程?
  3. 这在IE 10中如何运作?
  4. 以下是我的一些代码: HTML:

    <div class="container">
        <div id="div1" class="main slide current"> ... </div>
        <div id="div2" class="main slide future"> ... </div>
        <div id="div3" class="main slide future"> ... </div>
    </div>
    

    的CSS:

    .container {
        height: 100%;
        margin-left:auto;
        margin-right:auto;
        width:800px;
        overflow: visible;
        visibility: visible;
        -webkit-transform-style: preserve-3d;
        -moz-transform-style: preserve-3d;
        transform-style: preserve-3d;
    }
    .main{
        border: 1px solid;
        border-color: white;
        border-radius: 15px 15px 0 0 ;
        width: 100%;
        min-height: 450px;
        text-align: center;
        padding: 5px;
    }
    
    .slide {
        width: 800px;
        height: 450px;
        -webkit-transition: -webkit-transform 0.8s ease-in-out, opacity 1.2s ease-in-out;
        -moz-transition: -moz-transform 0.8s ease-in-out, opacity 1.2s ease-in-out;
        -webkit-box-orient: vertical;
        -moz-box-orient: vertical;
        box-orient: vertical;
        -webkit-box-sizing: content-box;
        -moz-box-sizing: content-box;
        box-sizing: content-box;
        overflow: hidden;
        display: none;
        position: absolute;
    }
    .slide.past {
        z-index: 8;
        visibility: visible;
        display: block;
        opacity: 0;
        -webkit-transform: translateZ(-400px) rotateY(-90deg) translateZ(400px);
        -moz-transform: translateZ(-400px) rotateY(-90deg) translateZ(400px);
        -o-transform: translateZ(-400px) rotateY(-90deg) translateZ(6400px);
        transform: translateZ(-400px) rotateY(-90deg) translateZ(400px);
    }
    .slide.current {
        z-index: 9;
        visibility: visible;
        display: block;
        opacity: 1;
        -webkit-transform: translateZ(-400px) rotateY(0deg) translateZ(400px);
        -moz-transform: translateZ(-400px) rotateY(0deg) translateZ(400px);
        -o-transform: translateZ(-400px) rotateY(0deg) translateZ(400px);
        transform: translateZ(-400px) rotateY(0deg) translateZ(400px);
    }
    .slide.future {
        z-index: 8;
        visibility: visible;
        display: block;
        opacity: 0;
        -webkit-transform: translateZ(-400px) rotateY(90deg) translateZ(400px);
        -moz-transform: translateZ(-400px) rotateY(90deg) translateZ(400px);
        -o-transform: translateZ(-400px) rotateY(90deg) translateZ(400px);
        transform: translateZ(-400px) rotateY(90deg) translateZ(400px);
    }
    

    脚本:

    $("#div1").attr("class", "main slide future");
    $("#div2").attr("class", "main slide current");
    

1 个答案:

答案 0 :(得分:0)

HTML

<h1>Slider</h1>
<div id="slider">
  <a href="#" class="control_next">>></a>
  <a href="#" class="control_prev"><</a>
  <ul>
    <li>SLIDE 1</li>
    <li style="background: #aaa;">SLIDE 2</li>
    <li>SLIDE 3</li>
    <li style="background: #aaa;">SLIDE 4</li>
  </ul>  
</div>

<div class="slider_option">
  <input type="checkbox" id="checkbox">
  <label for="checkbox">Autoplay Slider</label>
</div> 

CSS

html {
  border-top: 5px solid #fff;
  background: #58DDAF;
  color: #2a2a2a;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Open Sans';
}

h1 {
  color: #fff;
  text-align: center;
  font-weight: 300;
}

#slider {
  position: relative;
  overflow: hidden;
  margin: 20px auto 0 auto;
  border-radius: 4px;
}

#slider ul {
  position: relative;
  margin: 0;
  padding: 0;
  height: 200px;
  list-style: none;
}

#slider ul li {
  position: relative;
  display: block;
  float: left;
  margin: 0;
  padding: 0;
  width: 500px;
  height: 300px;
  background: #ccc;
  text-align: center;
  line-height: 300px;
}

a.control_prev, a.control_next {
  position: absolute;
  top: 40%;
  z-index: 999;
  display: block;
  padding: 4% 3%;
  width: auto;
  height: auto;
  background: #2a2a2a;
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  font-size: 18px;
  opacity: 0.8;
  cursor: pointer;
}

a.control_prev:hover, a.control_next:hover {
  opacity: 1;
  -webkit-transition: all 0.2s ease;
}

a.control_prev {
  border-radius: 0 2px 2px 0;
}

a.control_next {
  right: 0;
  border-radius: 2px 0 0 2px;
}

.slider_option {
  position: relative;
  margin: 10px auto;
  width: 160px;
  font-size: 18px;
}

的javascript

jQuery(document).ready(function ($) {

  $('#checkbox').change(function(){
    setInterval(function () {
        moveRight();
    }, 3000);
  });

    var slideCount = $('#slider ul li').length;
    var slideWidth = $('#slider ul li').width();
    var slideHeight = $('#slider ul li').height();
    var sliderUlWidth = slideCount * slideWidth;

    $('#slider').css({ width: slideWidth, height: slideHeight });

    $('#slider ul').css({ width: sliderUlWidth, marginLeft: - slideWidth });

    $('#slider ul li:last-child').prependTo('#slider ul');

    function moveLeft() {
        $('#slider ul').animate({
            left: + slideWidth
        }, 200, function () {
            $('#slider ul li:last-child').prependTo('#slider ul');
            $('#slider ul').css('left', '');
        });
    };

    function moveRight() {
        $('#slider ul').animate({
            left: - slideWidth
        }, 200, function () {
            $('#slider ul li:first-child').appendTo('#slider ul');
            $('#slider ul').css('left', '');
        });
    };

    $('a.control_prev').click(function () {
        moveLeft();
    });

    $('a.control_next').click(function () {
        moveRight();
    });

});