Swiper实现全屏视觉差轮播

Swiper作为当代流行的js框架,非常受到青睐,这里演示swiper在pc端全屏视觉轮播的效果,这也是pc端常用的一种特性

一  以教师节为主题的一个全屏轮播

  1 首先加载插件,需要用到的文件有swiper.min.js和swiper.min.css文件以及jquery-1.11.3.min.js官网都有(可以下载完整的压缩文件)

 <link rel="stylesheet" href="css/swiper.min.css" >
      <script src="js/jquery-1.11.3.min.js"></script>
     <script src="js/swiper.min.js"></script>

2  .HTML内容

//四张图片轮播 这里说一下全屏轮播的思想,首先,全屏轮播有两种方式来显示图片

1  使用img标签:使用img属性如果想让图片能够全屏展示,同时图片内容居中,我们需要设置width:100%,但是这样设置会使得你的图片等比的压缩,有时候达不到我们想要的效果,

你也可以采取定位来放置图片,但是在不同浏览器之间有些许瑕疵,(很多网站都是用过img属性来设置,也可以采纳)

2  使用background属性:这是我常用的一个方法,分享给大家,我们将要展示的图片设置为背景图片,(很多网站的图片都是链接,因此放在a中)设置属性a{display:block;height:‘图片高度’)

同时在标签中加入 style=" background: url(xxx) no-repeat center "样式,就能使得图片满屏并且内容居中,可以通过下面代码看一下

    <div class="banner">
       <div class="swiper-container myswiper">
            <div class="swiper-wrapper">
                <div class="swiper-slide">
                    <a href="#" style=" background: url(image/2.jpg) no-repeat center ">
                    </a>
                </div>
                <div class="swiper-slide"  style=" background: url(image/4.jpg) no-repeat center ">
                    <a href="#">
                    </a>
                </div>
                <div class="swiper-slide"  style=" background: url(image/2.jpg) no-repeat center ">
                    <a href="#">
                    </a>
                </div>
                <div class="swiper-slide"  style=" background: url(image/4.jpg) no-repeat center ">
                    <a href="#">
                    </a>
                </div>

      </div>
    <!-- 如果需要分页器 -->
    <div class="swiper-pagination"></div>

    <!-- 如果需要导航按钮 -->
    <div class="swiper-button-prev  mySwiperBut"></div>
    <div class="swiper-button-next  mySwiperBut"></div>
    </div>//可以修改一下按钮样式,这里不细说,见上一节

4.初始化Swiper

   <script>
  var mySwiper = new Swiper (‘.swiper-container‘, {
    // direction: ‘vertical‘,//默认水平
    loop: true,
    autoplay:true,
    effect:"fade",//淡入淡出效果
    parallax:"true",//产生视觉差

    // 如果需要分页器
    pagination: {
      el: ‘.swiper-pagination‘,
      clickable: true,
      clickableClass : ‘my-pagination-clickable‘,

    },

    // 如果需要前进后退按钮
    navigation: {
      nextEl: ‘.swiper-button-next‘,
      prevEl: ‘.swiper-button-prev‘,
    },

  })
  </script>

二 视觉差效果(其实这个很简单,在API文档中介绍了)

 parallax

设置为true开启视差效果。

效果可以应用于container或slide的子元素。当应用于container的子元素(常用于视差背景图),每次切换时视差效果仅有设定值的slide个数-1分之1

1.视差位移变化
在所需要的元素上增加data-swiper-parallax属性(与Swiper切换方向相同)或data-swiper-parallax-x (x方向) data-swiper-parallax-y(y方向)

data-swiper-parallax接受两种类型的参数。
          number(单位:px),如-300,从右边300px进入左边出去。
          percentage(百分比),移动距离=该元素宽度 * percentage。

2.视差透明度变化
在所需要的元素上增加data-swiper-parallax-opacity属性。可选值0-1,如0.5,从半透明进入半透明出去

3.视差缩放变化
在所需要的元素上增加data-swiper-parallax-scale属性。可选值如0.5,从一半大小进入一半大小出去

还可通过data-swiper-parallax-duration设定视差动画持续时间(ms)。默认值是Swiper的speed,与切换时间同步。

*设定透明度或缩放必须同时设定位移,否则无效(4.0.5) <div data-swiper-parallax="0" data-swiper-parallax-opacity="0.5" >透明度变化</div>

视觉差演示代码(直接在上面全屏轮播进行的修改)//script中将视觉差开启设置为true,同时在内容中加入data-swiper-parallax="xxx"(xxx一般为负值)

    <div class="banner">
       <div class="swiper-container myswiper">
            <div class="swiper-wrapper">
                <div class="swiper-slide">
                    <a href="#" style=" background: url(image/2.jpg) no-repeat center ">
                        <div class="text" data-swiper-parallax="-100">
                              We are like lambs in a field, disporting themselves under the eye of the butcher,<br/>
                           who chooses out first one and then another for his prey. So it is that in our good <br/>
                           days we are all unconscious of the evil Fate may have presently in store for us — sickness, poverty,<br/>
                           mutilation, loss of sight or reason
                        </div>
                    </a>
                </div>
                <div class="swiper-slide"  style=" background: url(image/4.jpg) no-repeat center ">
                    <a href="#">
                        <div class="text" data-swiper-parallax="-200">//值为-200
                              We are like lambs in a field, disporting themselves under the eye of the butcher,<br/>
                           who chooses out first one and then another for his prey. So it is that in our good <br/>
                           days we are all unconscious of the evil Fate may have presently in store for us — sickness, poverty,<br/>
                           mutilation, loss of sight or reason
                        </div> //加入内容体现视觉差
                    </a>
                </div>
                <div class="swiper-slide"  style=" background: url(image/2.jpg) no-repeat center ">
                    <a href="#">
                       <div class="text" data-swiper-parallax="-300">
                              We are like lambs in a field, disporting themselves under the eye of the butcher,<br/>
                           who chooses out first one and then another for his prey. So it is that in our good <br/>
                           days we are all unconscious of the evil Fate may have presently in store for us — sickness, poverty,<br/>
                           mutilation, loss of sight or reason
                        </div>
                    </a>
                </div>
                <div class="swiper-slide"  style=" background: url(image/4.jpg) no-repeat center ">
                    <a href="#">
                     <div class="text" data-swiper-parallax="-400">
                              We are like lambs in a field, disporting themselves under the eye of the butcher,<br/>
                           who chooses out first one and then another for his prey. So it is that in our good <br/>
                           days we are all unconscious of the evil Fate may have presently in store for us — sickness, poverty,<br/>
                           mutilation, loss of sight or reason
                        </div>
                    </a>
                </div>
      </div>

完整代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>实现全屏的视觉差效果轮播</title>
      <link rel="stylesheet" href="css/swiper.min.css" >
      <script src="js/jquery-1.11.3.min.js"></script>
     <script src="js/swiper.min.js"></script>
     <style>
         *{
             margin:0px;
             padding:0px;
         }
         .banner{
             margin-top:40px;
         }
      .swiper-slide a{
          display: block;
          height: 500px;
          overflow: hidden;
          text-decoration: none;
      }
      .text{
          color: #000;
          font-size: 20px;
          position: absolute;
          left: 10%;
          top:50%;

      }
     </style>
</head>
<body>
    <div class="banner">
       <div class="swiper-container myswiper">
            <div class="swiper-wrapper">
                <div class="swiper-slide">
                    <a href="#" style=" background: url(image/2.jpg) no-repeat center ">
                        <div class="text" data-swiper-parallax="-100">
                              We are like lambs in a field, disporting themselves under the eye of the butcher,<br/>
                           who chooses out first one and then another for his prey. So it is that in our good <br/>
                           days we are all unconscious of the evil Fate may have presently in store for us — sickness, poverty,<br/>
                           mutilation, loss of sight or reason
                        </div>
                    </a>
                </div>
                <div class="swiper-slide"  style=" background: url(image/4.jpg) no-repeat center ">
                    <a href="#">
                        <div class="text" data-swiper-parallax="-200">
                              We are like lambs in a field, disporting themselves under the eye of the butcher,<br/>
                           who chooses out first one and then another for his prey. So it is that in our good <br/>
                           days we are all unconscious of the evil Fate may have presently in store for us — sickness, poverty,<br/>
                           mutilation, loss of sight or reason
                        </div>
                    </a>
                </div>
                <div class="swiper-slide"  style=" background: url(image/2.jpg) no-repeat center ">
                    <a href="#">
                       <div class="text" data-swiper-parallax="-300">
                              We are like lambs in a field, disporting themselves under the eye of the butcher,<br/>
                           who chooses out first one and then another for his prey. So it is that in our good <br/>
                           days we are all unconscious of the evil Fate may have presently in store for us — sickness, poverty,<br/>
                           mutilation, loss of sight or reason
                        </div>
                    </a>
                </div>
                <div class="swiper-slide"  style=" background: url(image/4.jpg) no-repeat center ">
                    <a href="#">
                     <div class="text" data-swiper-parallax="-400">
                              We are like lambs in a field, disporting themselves under the eye of the butcher,<br/>
                           who chooses out first one and then another for his prey. So it is that in our good <br/>
                           days we are all unconscious of the evil Fate may have presently in store for us — sickness, poverty,<br/>
                           mutilation, loss of sight or reason
                        </div>
                    </a>
                </div>

      </div>
    <!-- 如果需要分页器 -->
    <div class="swiper-pagination"></div>

    <!-- 如果需要导航按钮 -->
    <div class="swiper-button-prev  mySwiperBut"></div>
    <div class="swiper-button-next  mySwiperBut"></div>
    </div>
    <script>
  var mySwiper = new Swiper (‘.swiper-container‘, {
    // direction: ‘vertical‘,
    loop: true,
    autoplay:true,
    effect:"fade",
    parallax:"true",

    // 如果需要分页器
    pagination: {
      el: ‘.swiper-pagination‘,
      clickable: true,
      clickableClass : ‘my-pagination-clickable‘,

    },

    // 如果需要前进后退按钮
    navigation: {
      nextEl: ‘.swiper-button-next‘,
      prevEl: ‘.swiper-button-prev‘,
    },

  })
  </script>
</body>
</html>//图片地址http://show.huitu.com/pic/20180904/r38905.jpg

原文地址:https://www.cnblogs.com/qianqian-it/p/9593389.html

时间: 2024-08-02 16:57:15

Swiper实现全屏视觉差轮播的相关文章

jQuery和CSS3超酷全屏视觉差幻灯片特效

这是一款效果非常炫酷的jQuery和CSS3全屏视觉差幻灯片特效.该幻灯片采用半透明的遮罩层作为文字说明层.在幻灯片切换时,文字有动态放大的效果.图片和文字的移动形成了一种微妙的视觉差效果. 效果演示:http://www.htmleaf.com/Demo/201506162049.html 下载地址:http://www.htmleaf.com/jQuery/Slideshow-Scroller/201506162048.html

非常优秀的swiper插件————幻灯片播放、图片轮播

幻灯片播放.图片轮播----非常优秀的swiper插件 http://www.idangero.us/sliders/swiper/index.php    插件主页 http://www.idangero.us/sliders/swiper/api.php        插件API http://www.idangero.us/sliders/swiper/demos.php   插件DEMO <!DOCTYPE html> <html> <head> <met

支持触屏的jQuery轮播图插件

移动轮播图我看到两类, 一款是无线天猫的m.tmall.com和携程,实现了无缝轮播. 一款是蘑菇街的,没有实现无缝轮播. 我自己重写一个,类似天猫.不过功能上简单点,只实现支持触屏和无缝轮播. 1.页面代码 1 <!DOCTYPE html> 2 <html xmlns="http://www.w3.org/1999/xhtml" lang="UTF-8"> 3 <head> 4 <meta charset="U

swiper在angularjs中使用循环轮播失效的解决方法

bug描述:我在anjularjs 中使用了swiper轮播图,通过动态获取到数据插入swiper-slide中,我在swiper初始化中设置了loop(循环),但是在出现了一点小问题,swiper会失效,划不动,当我设置固定的数据通过ng-src 插入到swiper-silde中,会正常轮播,但是第一张图会出现空白.通过查询了资料,发现swiper和angularjs执行的机制是不同的,swiper的机制是:初始化的时候自动扫描swiper-wrapper类下有多少个swiper-slide类

jquery全屏背景轮播切换的登录页

很大气漂亮的注册登录页面模板,带背景全屏轮播JS特效,基于jQuery实现,可左右按钮实现背景全屏切换,全屏效果是基于背景图片平铺,插件支持自动切换播放. 演示    下载 <!DOCTYPE html> <html> <head> <title>jquery带全屏背景图片轮播切换的注册登录页面-素材吧</title> <meta name="keywords" content="jQuery背景全屏轮播,JS

使用swiper轮播图进行数据传输的时候遇到的坑

说起swiper,简直是一款轮播图神器,本人是非常喜欢的,最近在向资深的小哥哥学习模拟数据传输,然后swiper就出现样式错乱和不能点击切换等各种问题,谁能告诉我发生了什么吗?我是谁?我在哪? 好吧,经过网上一番找资料,还是没找到,最后一位神人告诉我说,你取到数据后在初始化swiper看看!!!!!!! 神奇的事情发生了,一切恢复正常. 解决办法: 取到数据后再new Swiper 原文地址:https://www.cnblogs.com/klkitty/p/8717961.html

vue中异步请求渲染问题(swiper不轮播)(在开发过程中遇到过什么问题)

问题描述: 用vue封装一个swiper组件的时候,发现轮播图不能轮播了. 原因: 异步请求的时间远大于生命周期执行的时间,mounted初始化DOM时数据未返回,渲染数据是空数组,导致轮播图的容器层宽度为0,渲染轮播图不能滚动. 解决思路: 数据返回之后再做初始化操作. 解决方法: 一.容器没有宽度,就想着给容器设置一个宽度,但是一旦设置死数据了后期维护起来很麻烦. 二.设置一个定时器,延长等待的时间,但是无法确定网络请求的时间,这样操作严么会等待时间过长,影响用户体验,要么是还没有请求完就去

vue03----生命周期、nextTick()、ref、filter、computed、vue中异步请求渲染问题(swiper不轮播)(在开发过程中遇到什么问题、踩过的坑)

### 1.vue的组件和实例都有生命周期,而且是一样的 生命周期:(组件从创建到销毁的过程) 创建 挂载 更新 销毁 组件到达某一个阶段就会自动触发某一些函数,这个函数就叫生命周期的钩子函数. 创建:组件创建的时候触发 beforeCreate created     组件刚创建的数据请求 挂载:创建完成挂载前后触发 beforeMount mounted     DOM的初始化操作 更新:数据发生改变的时候触发 beforeUpdate updated     数据的变化监听,尽量不要在这里

带原点的图片轮播

<html xmlns="http://www.w3.org/1999/xhtml"><head><title>jquery全屏banner自动轮播切换</title><script type="text/javascript" src="/ajaxjs/jquery-1.6.2.min.js"/></script><script type="text/jav