jQuery bxCarousel实现图片滚动切换效果

BxCarousel是一个具有众多配置且易用的Jquery图片滚动插件,特征主要有:

◆ 可以指定显示的元素总数

◆ 可以指定每次滚动的元素个数

◆ 自动播放模式

◆ 前一张/后一张按钮控制图片流动

参数含义:

display_num:显示元素的数量,几张图片

move:单击左右控制键时,移动的元素个数,此处为移动2张图片

prev_image:上一元素按钮图片

next_image:下一元素按钮图片

margin:图片之间的间隙,一般设为10px

auto:自动滚动效果

controls:是否显示左右控制按钮,此处为false,表示不显示左右控制按钮

auto_hover:鼠标悬停到轮播区域时,是否停止图片轮播

BxCarousel使用和配置

首先HTML代码需要符合以下格式

<ul>
    <li>first piece of content</li>
    <li>second piece of content</li>
    <li>third piece of content</li>
    <li>fourth piece of content</li>
    <li>bxCarousel can accept an unlimited number of elements</li>
</ul>

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 <li> 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属性值小于持续时间。

实例代码:

 

<!DOCTYPE html>

<html>

<head>

<meta content="text/html; charset=utf-8" http-equiv="Content-Type" >

<title></title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<script type="text/javascript" src="js/bxCarousel.js"></script>

<script type="text/javascript">

jQuery(function(){

	jQuery('#demo1').bxCarousel({

		display_num: 4, //

		move: 1, 

		auto: true, 

		controls: false, //此处为false,表示不显示左右箭头控制按钮

		margin: 10,

		auto_hover: true //鼠标悬停到轮播区域时,是否停止图片轮播

	});

	jQuery('#demo2').bxCarousel({

		display_num: 4, 

		move: 4,

		margin: 10 

	});

});

</script>

<script type="text/javascript" src="./video/js/mootools.js"></script>

<script type="text/javascript" src="./video/js/swfobject.js"></script>

<script type="text/javascript" src="./video/js/videobox.js"></script>

<link rel="stylesheet" type="text/css" href="./video/css/videobox.css" >

<style type="text/css">

.pic, .vd{

	width:200px;

	height:200px;	

	margin:0 auto;

}

.pic a, .vd a{

	display:block;

	width:200px;

	height:200px;	

	text-align:center;

	margin:0 auto;

}

.pic{

	background:url("http://i0.sinaimg.cn/home/2013/0513/U2727P30DT20130513082202.jpg") no-repeat scroll 0  0 transparent;

}

.vd{

	background:url("http://i0.sinaimg.cn/home/2013/0512/U1345P30DT20130512114119.jpg") no-repeat scroll 0  0 transparent;

}

.nav,.main,.imgcollc ,.footer{

	width:910px;

	margin:0 auto;

	text-align:center;

}

/*如果要使用方向按钮导航,则需要设置.bx_wrap a.prev和.bx_wrap a.next的样式。*/

a {color: #424242;text-decoration: none;}

ul,li,ol{padding:0;margin:0;list-style:none;}

.bx_wrap {margin-left: 30px; margin-top:10px;} 

.bx_wrap ul img { border: 2px solid #ddd; } 

.bx_wrap ul li{text-align:center;float:left;width:140px;height:119px;overflow:hidden;} 

.bx_wrap ul li a:hover{text-decoration:none; color:#f30;} 

.bx_wrap a.prev {width:20px;height:24px;line-height:24px;outline-style:none;outline-width: 0; position:absolute; top:45px; left:5px; text-indent:-999em; background: url(img/arr_left.gif)  no-repeat;} 

.bx_wrap a.next {width:20px;height:24px;line-height:24px; left:623px;position: absolute; top:45px; text-indent:-999em; background:url('img/arr_right.gif') no-repeat;} 

.demo {width: 650px;height: 134px;margin: 40px auto;position: relative;border: 1px solid #d3d3d3;overflow:hidden;

}



</style>



</head>

<body>



<div class="nav">





</div>

<div class="main">

	<h2 class="top_title"><a href="http://www.feiliu.com/">jQuery实现的视频窗口伸缩、图片滚动切换效果</a></h2>

	<div class="pic">

		<a onfocus="blur()" id="img" href="http://imgsrc.baidu.com/forum/pic/item/ed178044ad345982578b3fa90cf431adcaef84d7.jpg"  rel="vidbox 640 376" title="test jpg"></a>

	</div>

	<div class="vd">

		<a onfocus="blur()" id="vd" href="http://www.novelstudios.com/media/Visions_CellPhone.mov"  rel="vidbox 640 376" title="test video"></a>

	</div>

</div>

<div class="imgcollc">

	<div class="demo">

		<ul id="demo1">

			<li><a href="#"><img  alt="#" width="140" height="94" src="img/s1.jpg"><br/>图片1</a></li>

			<li><a href="#"><img  alt="#" width="140" height="94" src="img/s2.jpg"><br/>图片2</a></li>

			<li><a href="#"><img  alt="#" width="140" height="94" src="img/s3.jpg"><br/>图片3</a></li>

			<li><a href="#"><img  alt="#" width="140" height="94" src="img/s4.jpg"><br/>图片4</a></li>

			<li><a href="#"><img  alt="#" width="140" height="94" src="img/s5.jpg"><br/>图片5</a></li>

			<li><a href="#"><img  alt="#" width="140" height="94" src="img/s6.jpg"><br/>图片6</a></li>

			<li><a href="#"><img  alt="#" width="140" height="94" src="img/s7.jpg"><br/>图片7</a></li>

			<li><a href="#"><img  alt="#" width="140" height="94" src="img/s1.jpg"><br/>图片1</a></li>

			<li><a href="#"><img  alt="#" width="140" height="94" src="img/s2.jpg"><br/>图片2</a></li>

			<li><a href="#"><img  alt="#" width="140" height="94" src="img/s3.jpg"><br/>图片3</a></li>

			<li><a href="#"><img  alt="#" width="140" height="94" src="img/s4.jpg"><br/>图片4</a></li>

			<li><a href="#"><img  alt="#" width="140" height="94" src="img/s5.jpg"><br/>图片5</a></li>

			<li><a href="#"><img  alt="#" width="140" height="94" src="img/s6.jpg"><br/>图片6</a></li>

			<li><a href="#"><img  alt="#" width="140" height="94" src="img/s7.jpg"><br/>图片7</a></li>

		</ul>



	</div>

    

	<div class="demo">

		<ul id="demo2">

			<li><a href="#"><img  alt="#" width="140" height="94" src="img/s1.jpg"><br/>图片1</a></li>

			<li><a href="#"><img  alt="#" width="140" height="94" src="img/s2.jpg"><br/>图片2</a></li>

			<li><a href="#"><img  alt="#" width="140" height="94" src="img/s3.jpg"><br/>图片3</a></li>

			<li><a href="#"><img  alt="#" width="140" height="94" src="img/s4.jpg"><br/>图片4</a></li>

			<li><a href="#"><img  alt="#" width="140" height="94" src="img/s5.jpg"><br/>图片5</a></li>

			<li><a href="#"><img  alt="#" width="140" height="94" src="img/s6.jpg"><br/>图片6</a></li>

		</ul>

	</div>

</div>

<div class="footer">Mobile</div>



</body>



</html>

 

本实例中同时实现了灯箱效果。由于采用videobox插件,对于图片和视频都支持。很多灯箱效果的脚本和插件,比如jQuery Lightbox PluginVideobox MooslideBox,,Shadowbox LightWindow 等等。

Videobox是一个只有6k大小的脚本,用于在页面中显示视频。Videobox使用swfobject来嵌入Flash。视频可以来自Youtube、Metacafe、Google Video、iFilm和自己设置的Flash。如果你要达到效果,必须使用videobox.js,mootools.js和swfobject脚.js这个三个脚本。

 

类似滚动滑动的插件还有bxSlider 等等,bxSlider是一个 jQuery 的插件,它可以实现 Slider 和滚动效果。这个插件使用非常简单,并且大小只有 8kb,非常轻量级,所以非常适合在站点和博客中使用。

 

你可能感兴趣的:(jquery)