zoukankan      html  css  js  c++  java
  • bootstrap轮播图

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>使用carousel</title>
    <!-- Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="/stylesheets/bootstrap.min.css">

    <!-- jQuery文件 -->
    <script src="/scripts/jquery.min.js"></script>

    <!-- Bootstrap 核心 JavaScript 文件 -->
    <script src="/scripts/bootstrap.min.js"></script>
    </head>
    <body>
    <div id="carousel-example-generic" class="carousel slide" data-ride="carousel" style="margin:10px;">
    <!-- Wrapper for slides -->
    <div class="carousel-inner" role="listbox">
    <div class="item active">
    <a href="javascript:void(0)">
    <img src="http://fun.datang.net/uploadpic/276e0c7bb66b46318c3bb9c59cad9411.jpg" style="300px;height:300px;" alt="图片一"/></a>
    <div class="carousel-caption">
    <h4 class="alpha">
    <a style="color:white;" href="javascript:void(0)">驴子跳</a>
    </h4>
    </div>

    </div>
    <div class="item">
    <a href="javascript:void(0)">
    <img src="http://img5.imgtn.bdimg.com/it/u=372265704,58471841&fm=21&gp=0.jpg" style="300px;height:300px;" alt="图片二"/>
    </a>
    <div class="carousel-caption">
    <h4 class="alpha">
    <a style="color:white;" href="javascript:void(0)">MarkDown</a>
    </h4>
    </div>
    </div>
    <div class="item">
    <a href="javascript:void(0)">
    <img src="http://img1.imgtn.bdimg.com/it/u=3318255286,2969027749&fm=23&gp=0.jpg" style="300px;height:300px;" alt="图片三"/>
    </a>
    <div class="carousel-caption">
    <h4 class="alpha">
    <a style="color:white;" href="javascript:void(0)">BootStrap</a>
    </h4>
    </div>
    </div>
    <!-- 控制按钮 -->
    <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
    </a>
    <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
    </a>
    </div>
    </body>
    </html>

    解决展示时图片变形的问题

    运行上节的代码我们发现插件中的图片发生了变形,分析其原因为:轮换插件中的图片使用的文章中的第一张图片,图片的大小不一,而轮播插件的大小基本是固定的,所以展示的时候图片出现了变形。下面看看怎么解决这个问题:

    1.引入Jqthumb.js

    在BootStrap中我们找不到解决办法,所以我们需要借助其它工具。Jqthumb插件是专门用来为图片生成缩略图的,它可以从图片中的任何坐标点开始取指定大小的图片区域作为图片的缩略图。你可以点击 https://github.com/pakcheong/jqthumb 来下载它,并将其应用到项目中(假设在当前项目中,jqthumb.js放置在scripts文件夹中):

    1. <script type="text/javascript" src="/scripts/jqthumb.js"></script>

    2.在图片加载(onload)的时候调用DrawImage()函数来生成缩略图

    DrawImage()函数正是基于jqthumb.js库的,注意该函数一定要写在轮换插件前,因为我们必须在图片加载前生成缩略图。DrawImage()函数代码如下:

    1. <!--导入插件-->
    2. <script type="text/javascript" src="/scripts/jqthumb.js"></script>
    3. <script>
    4. function DrawImage(hotimg)
    5. {
    6. $(hotimg).jqthumb({
    7. classname : 'jqthumb',
    8. width : '100%',//宽度
    9. height : '300px',//高度
    10. position : { y: '50%', x: '50%'},//从图片的中间开始产生缩略图
    11. zoom : '1',//缩放比例
    12. method : 'auto',//提交方法,用于不同的浏览器环境,默认为‘auto’
    13. });
    14. }
    15. </script>

    在上述代码中,我们使用了jqthumb,并且传入了相关初始化参数。调用了该函数后,在图片加载的时候,就会按照上述参数产生图片的缩略图,从而解决图片变形问题。由于缩略图是从原始图片的正中间开始往两边取得,所以该缩略图包含了图片的主要内容。(具体使用见右边详细代码)

  • 相关阅读:
    吴裕雄--天生自然python学习笔记:python 用 Tesseract 识别验证码
    吴裕雄--天生自然python学习笔记:python安装配置tesseract-ocr-setup-3.05.00dev.exe
    吴裕雄--天生自然python学习笔记:python 用 Open CV通过人脸识别进行登录
    吴裕雄--天生自然python学习笔记:python 用 Open CV抓取摄像头视频图像
    HDU4278 Faulty Odometerd
    最大流 总结
    HDU1411 欧拉四面体
    HDU3336 Count the string
    HDU1711
    HDU2203 亲和串
  • 原文地址:https://www.cnblogs.com/zhangxiaolei521/p/6282341.html
Copyright © 2011-2022 走看看