当前位置:Gxlcms > JavaScript > jQuerybxCarousel实现图片滚动切换效果示例代码_jquery

jQuerybxCarousel实现图片滚动切换效果示例代码_jquery

时间:2021-07-01 10:21:17 帮助过:18人阅读

BxCarousel是一个具有众多配置且易用的Jquery图片滚动插件,特征主要有:
◆ 可以指定显示的元素总数
◆ 可以指定每次滚动的元素个数
◆ 自动播放模式
◆ 前一张/后一张按钮控制图片流动
参数含义
display_num:显示元素的数量,几张图片
move:单击左右控制键时,移动的元素个数,此处为移动2张图片
prev_image:上一元素按钮图片
next_image:下一元素按钮图片
margin:图片之间的间隙,一般设为10px
auto:自动滚动效果
controls:是否显示左右控制按钮,此处为false,表示不显示左右控制按钮
auto_hover:鼠标悬停到轮播区域时,是否停止图片轮播
BxCarousel使用和配置
首先HTML代码需要符合以下格式
代码如下:


  • first piece of content

  • second piece of content

  • third piece of content

  • fourth piece of content

  • bxCarousel can accept an unlimited number of elements



jQuery代码需要符合以下格式
代码如下:

$(document).ready(function(){
$('ul').bxCarousel({
display_num: 4, // number of elements to be visible
move: 4, // number of elements to the shift the slides
speed: 500, // number in milliseconds it takes to finish slide animation
margin:0, // right margin to be applied to each
  • element (in pixels, although do not include "px")
    auto: false, // automatically play slides without a user click
    auto_interval: 2000, // the amount of time in milliseconds between each auto animation
    auto_dir: 'next', // direction of auto slideshow (options: 'next', 'prev')
    auto_hover: false, // determines if the slideshow will stop when user hovers over slideshow
    next_text: 'next', // text to be used for the 'next' control
    next_image: '', // image to be used for the 'next' control
    prev_text: 'prev', // text to be used for the 'prev' control
    prev_image: '', // image to be used for the 'prev' control
    controls: true // determines if controls will be displayed
    });
    });

  • div.bx_container和div.bx_wrap等html元素是js生成加上的,在使用bxCarousel插件时,为了达到视觉美感,要记得为div.bx_container和div.bx_wrap及其内部子元素设定需要的CSS Style。
    还有注意的是,
    bxCarousel是个无限循环机制,不停的点击next按钮看看html发生了什么变化!!
    bxCarousel不只针对图片,对其他任何html元素均起作用。
    如果开启auto属性,注意一定要保证speed属性值小于持续时间。
    实例代码
    代码如下: