【问题标题】:HTML5 slide show effectHTML5幻灯片效果
【发布时间】:2014-05-11 19:28:02
【问题描述】:

我看过一些幻灯片,比如 http://slides.html5rocks.comhttp://www.htmlfivewow.com

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

  1. 制作动画时,div 没有 3D 样式,它只是移动和旋转。事实上,http://slides.html5rocks.com 在我的 Firefox 中没有 3D 效果,而在 Chrome 中有。
  2. 有教程吗?
  3. 如何在 IE 10 中工作?

这是我的一些代码: 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");

【问题讨论】:

    标签: javascript css html


    【解决方案1】:

    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();
        });
    
    });    
    

    【讨论】:

    • 感谢您的回复。但是没有3D风格。特别是,我的意思是,向左或向右移动时 3D 旋转,同时改变幻灯片的大小。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-02
    • 2012-10-10
    • 1970-01-01
    • 1970-01-01
    • 2018-03-11
    • 1970-01-01
    相关资源
    最近更新 更多