jQuery插件bgStretcher.js实现全屏背景特效


Posted in Javascript onJune 05, 2015

bgStretcher 2011 (Background Stretcher)是一个jQuery的插件,可以为你的网页添加多张背景图,且多个背景图能够自动切换,同时背景图大小可以自适应浏览器窗口的大小。背景图的切换效果有淡入淡出,滚动,幻灯,其中选用滚动和幻灯时,可以选择方向,上下左右,或者左上右下,右上左下。图片切换顺序也可以设置正向,反向或者随机。更多选项就看你自己慢慢研究了。

bgStretcher是一个jQuery插件,它允许你添加一个大图像(或一组图像)到您的网页的背景,并会按比例调整图像大小,以填满整个窗口区域。如果使用多个图像模式(幻灯片的速度和持续时间可配置),该插件将作为幻灯片。

插件特点:

脚本文件简洁,设置简单;支持所有新版浏览器;支持单张或者多张图片。

插件使用:

首先,你当然要把插件先下载再说,插件包里已经包含了所需要的JS文件。

然后,把下面的代码插入到你网页的<head>和</head>之间,这样后面才能使用插件,注意代码中的路径,至于是相对路径还是绝对路径看你实际需要。

<link rel="stylesheet" type="text/css" href="./main.css" />
<link rel="stylesheet" type="text/css" href="../bgstretcher.css" />
<script type="text/javascript" src="../jquery-1.5.2.min.js"></script>
<script type="text/javascript" src="../bgstretcher.js"></script>

接着把下面的代码,插入到上面代码之后,来初始化 bgStretcher 插件,要告知插件在哪个元素上起作用,同时可以配置插件的选项。同样,注意代码中的图片路径不要出错。

<script type="text/javascript">
 $(document).ready(function(){
 
  // Initialize Backgound Stretcher 
 $('.demoo').bgStretcher({
 images: ['images/sample-1.jpg', 'images/sample-2.jpg', 'images/sample-3.jpg', 'images/sample-4.jpg', 'images/sample-5.jpg', 'images/sample-6.jpg'],
 imageWidth: 800, 
 imageHeight: 400, 
 slideDirection: 'N',
 slideShowSpeed: 1000,
 transitionEffect: 'fade',
 sequenceMode: 'normal',
 });
 
 });
</script>

该插件不只是用于整个网页背景哦,还可以用于某个网页元素,当然,起码这个元素能设置背景,比如DIV之类等等。选择网页元素是通过ID或者Class来的,应为BODY这个元素名是网页里唯一的元素名,也就是给整个网页设置背景。如果是给页面某一个DIV块设置背景,那你需要给这个DIV定义一个ID或者知道它的样式Class名也行,ID和Class名最好是唯一的,要不然效果很惊人。

插件选项:

配置选项 缺 省 值 选项说明
imageContainer bgstretcher bgStretcher will automatically build structure for the images list in a DOM tree. This parameter is ID for the images holder. Try inspecting the tree with a FireBug to get an idea how it's constructed.
resizeProportionally true Indicates if background image(s) will be resized proportionally or not.
resizeAnimate false Indicates if background image(s) will be resized with animation. (Be careful, this may slow down some PCs if your images are large.)
images empty An array containing list of images to be displayed on page's background.
imageWidth 1024 Original image's width.
imageHeight 768 Original image's height.
maxWidth auto Maximum image's width.
maxHeight auto Maximum image's height.
nextSlideDelay 3000 (3 seconds) Numeric value in milliseconds. The parameter sets delay until next slide should start.
slideShowSpeed normal Numeric value in milliseconds or jQuery string value (‘fast', ‘normal', ‘slow'). The parameter sets the speed of transition between images.
slideShow true Allows or disallows slideshow functionality.
transitionEffect fade Transition effect (use also: none, simpleSlide, superSlide).
slideDirection N Slide Diraction: N ? north, S ? south, W ? west, E ? East (if transitionEffect = superSlide use also: NW, NE, SW, SE).
sequenceMode normal Sequence mode (use also: back, random)
buttonPrev empty Previous button CSS selector
buttonNext empty Next button CSS selector
pagination empty CSS selector for pagination
anchoring ‘left top' Anchoring bgStrtcher area regarding window
anchoringImg ‘left top' Anchoring images regarding window
preloadImg false For Preload images use true
stratElementIndex 0 Start element index
callbackfunction null Name of callback function

插件方法:

方法名称 方法说明
$(objID).bgStretcher.play()                 Resume background slideshow
$(objID).bgStretcher.pause()              Pause background slideshow
$(objID).bgStretcher.sliderDestroy()   Destroy background slideshow

浏览器兼容性:

MS Internet Explorer 6, 7, 8, 9
Mozilla Firefox 2, 3, 4
Opera 9+
Apple Safari
Google Chrome

以上所述就是本文的全部内容了,希望大家能够喜欢。

Javascript 相关文章推荐
Array对象方法参考
Oct 03 Javascript
在线编辑器中换行与内容自动提取
Apr 24 Javascript
jquery插件制作 提示框插件实现代码
Aug 17 Javascript
javascript中普通函数的使用介绍
Dec 19 Javascript
jquery队列queue与原生模仿其实现方法分享
Mar 25 Javascript
JS实现简单路由器功能的方法
May 27 Javascript
jquery地址栏链接与a标签链接匹配之特效代码总结
Aug 24 Javascript
AngularJS入门教程之过滤器详解
Aug 19 Javascript
vue移动端路由切换实例分析
May 14 Javascript
判断“命令按钮”是否被鼠标单击详解
Jul 31 Javascript
使用axios请求时,发送formData请求的示例
Oct 29 Javascript
基于canvasJS在PHP中制作动态图表
May 30 Javascript
js+html5绘制图片到canvas的方法
Jun 05 #Javascript
简介JavaScript中valueOf()方法的使用
Jun 05 #Javascript
jQuery插件jRumble实现网页元素抖动
Jun 05 #Javascript
js+html5获取用户地理位置信息并在Google地图上显示的方法
Jun 05 #Javascript
jquery插件NProgress.js制作网页加载进度条
Jun 05 #Javascript
JavaScript中toString()方法的使用详解
Jun 05 #Javascript
javascript实现倒计时并弹窗提示特效
Jun 05 #Javascript
You might like
php 特殊字符处理函数
2008/09/05 PHP
在Yii框架中使用PHP模板引擎Twig的例子
2014/06/13 PHP
jQuery.buildFragment使用方法及思路分析
2013/01/07 Javascript
jQuery实现点击该行即可删除HTML表格行
2014/10/17 Javascript
BootStrap和jQuery相结合实现可编辑表格
2016/04/21 Javascript
Bootstrap所支持的表单控件实例详解
2016/05/16 Javascript
jQuery  ready方法实现原理详解
2016/10/19 Javascript
JavaScript中this的用法实例分析
2016/12/19 Javascript
Angular2使用jQuery的方法教程
2017/05/28 jQuery
JS实现经典的中国地区三级联动下拉菜单功能实例【测试可用】
2017/06/06 Javascript
在 Vue.js中优雅地使用全局事件的方法
2019/02/01 Javascript
详解Vue中的scoped及穿透方法
2019/04/18 Javascript
javascript实现点击产生随机图形
2021/01/25 Javascript
[42:32]DOTA2上海特级锦标赛B组资格赛#2 Fnatic VS Spirit第二局
2016/02/27 DOTA
详解Python 正则表达式模块
2018/11/05 Python
python实现mean-shift聚类算法
2020/06/10 Python
Django如何实现密码错误报错提醒
2020/09/04 Python
一个入门级python爬虫教程详解
2021/01/27 Python
CSS3中Animation动画属性用法详解
2016/07/04 HTML / CSS
诗普兰迪官方网站:Splendid
2018/09/18 全球购物
计算机软件个人的自荐信范文
2013/12/01 职场文书
行政部总经理岗位职责
2014/01/04 职场文书
个人自我评价和职业目标
2014/01/24 职场文书
八年级数学教学反思
2014/01/31 职场文书
市级青年文明号申报材料
2014/05/26 职场文书
高中运动会广播稿
2014/09/16 职场文书
企业务虚会发言材料
2014/10/20 职场文书
鼋头渚导游词
2015/02/05 职场文书
南京南京观后感
2015/06/02 职场文书
叶问观后感
2015/06/15 职场文书
休学证明范本
2015/06/19 职场文书
运动会入场词
2015/07/18 职场文书
婚宴新娘致辞
2015/07/28 职场文书
python如何读取.mtx文件
2021/04/22 Python
springboot中rabbitmq实现消息可靠性机制详解
2021/09/25 Java/Android
CSS 鼠标选中文字后改变背景色的实现代码
2023/05/21 HTML / CSS