基于 JQUERY 网页 banner
demo.html
<html>
<head>
<title>demo</title>
<link href="css/PaPaBanner.css" rel="stylesheet" />
<script src="jquery-1.8.2.js"></script> </head> <body> <div id="banner"> <div class="bannerImage" style="background-image: url(images/11.jpg);" data-url="http://www.baidu.com"></div> <div class="bannerImage" style=" background-image: url(images/12.jpg);" data-url=""></div> <div class="bannerImage" style=" background-image: url(images/13.jpg);" data-url="http://www.baidu.com"></div> <div class="bannerImage" style=" background-image: url(images/14.jpg);"></div> </div>
<script src="PaPaBanner.js"></script>
</body>
</html>
PaPaBanner.js
$(function () {
banner.init();
});
var config = {
bannerId: "banner",
height: 400,
autoPlayInterval:3000
};
var banner = {
index: 0,
count: 0,
init: function () {
var obj = this;
this.count = $("#" + config.bannerId + " .bannerImage").size();
$("#" + config.bannerId).height(config.height);
$("#" + config.bannerId + " .bannerImage").height(config.height);
this.setUrl();
this.setNavigator();
this.setNavigatorHover();
this.setIndex();
this.timer = setInterval(function () { obj.autoPlay(); }, config.autoPlayInterval);
},
autoPlay: function () {
this.index++;
if (this.index >= this.count) {
this.index = 0;
}
this.setIndex();
},
setIndex: function() {
$("#" + config.bannerId + " .btn li").eq(this.index).addClass("lihover").siblings("li").removeClass("lihover");
$("#" + config.bannerId + " .bannerImage").eq(this.index).fadeIn(2000).siblings("div").fadeOut(2000);
},
setUrl: function() {
$("#" + config.bannerId + " div").each(function () {
var url = $(this).attr("data-url");
if ($.trim(url) == "" || url == undefined) {
return;
}
$(this).append("<a href='" + url + "' style='display:block;height:" + config.height + "px;width:100%;' target='_blank' ></a>");
});
},
setNavigator: function() {
$("#" + config.bannerId).append("<ul class='btn'></ul>");
for (var i = 0; i < this.count; i++) {
$("#" + config.bannerId + " .btn").append("<li data-pos='" + i + "' ></li>");
}
},
setNavigatorHover: function () {
var obj = this;
$("#" + config.bannerId + " .btn li").hover(function () {
clearInterval(obj.timer);
obj.index = $(this).attr("data-pos");
obj.setIndex();
}, function () {
obj.timer = setInterval(function () { obj.autoPlay(); }, config.autoPlayInterval);
});
}
};
PaPaBanner.css
#banner {
width: 100%;
margin: 0;
padding: 0;
position: relative;
height: 500px;
}
.bannerImage {
width: 100%;
height: 500px;
position: absolute;
top: 0px;
left: 0px;
background-repeat: no-repeat;
}
#banner .btn{ position: absolute;left: 70%;bottom:10px; display:inline-block;margin: 0px 0px;padding:2px 10px; background-color:#ccc;border-radius:11px;}
.btn li{float:left;height:16px;width:16px;list-style: none;text-align: center;margin: 0px;padding: 0px;margin-left: 5px;background: url(../images/1.png) no-repeat ; }
.btn .lihover{ background: url(../images/2.png) no-repeat ; }
ok, https://github.com/jinshuai/PaPaBanner
基于 JQUERY 网页 banner的更多相关文章
- 基于Jquery的banner轮播插件,简单粗暴
新手练习封装插件,觉着在前端这一块的轮播比较多,各种旋转木马一类的3D旋转,技术不够,所以封装了一个简单的banner轮播插件,功能也比较简单,就是左右向的轮播. 先挂地址https://github ...
- 基于jquery打造的网页右侧自动收缩浮动在线客服代码
基于jquery打造的网页右侧自动收缩浮动在线QQ客服代码, 当前比较流行的一款QQ在线jquery特效代码, 代码中还带有IE6下PNG图片透明的特效,如果想研究IE6下PNG透明的同学也可以下载研 ...
- 基于jQuery仿QQ音乐播放器网页版代码
基于jQuery仿QQ音乐播放器网页版代码是一款黑色样式风格的网页QQ音乐播放器样式代码.效果图如下: 在线预览 源码下载 实现的代码. html代码: <div class="m ...
- 基于jquery仿天猫分类导航banner切换
分享一款基于jquery天猫分类导航banner切换.这是一款仿最新天猫商品分类导航控制banner图片切换代码.效果图如下: 在线预览 源码下载 部分代码: <div class=&quo ...
- 基于jquery和svg超炫的网页动画
今天给大家分享一款基于jquery和svg超炫的网页动画.这款动画效果非常炫.下面还有重播.慢速.和反向动画按钮.效果非常漂亮.一起看下效果图: 在线预览 源码下载 实现的代码. html代码: ...
- 基于jQuery 常用WEB控件收集
Horizontal accordion: jQuery 基于jQuery开发,非常简单的水平方向折叠控件. Horizontal accordion: jQuery jQuery-Horizonta ...
- 一些基于jQuery开发的控件
基于jQuery开发,非常简单的水平方向折叠控件.主页:http://letmehaveblog.blogspot.com/2007/10/haccordion-simple-horizontal-a ...
- 基于jQuery的自适应图片左右切换
效果预览:http://hovertree.com/code/jquery/smjv6d0n.htm 基于jQuery编写的横向自适应幻灯片切换特效 全屏自适应jquery焦点图切换特效,在IE6这个 ...
- 使用 Sticky-Kit 实现基于 jQuery 的元素固定效果
元素固定效果在网页中应用得很多,比较常见的使用场景有改进导航,显示广告.Sticky-Kit 是一个非常方便的 jQuery 插件,简化了创建/管理粘元素,有复杂的使用功能.这些功能包括:处理多个固定 ...
随机推荐
- uvalive 4992 Jungle Outpost
题意:一个凸边型,目标在凸边型内且最优.问最多删除几个点使目标暴露在新凸边型外面. 思路:二分+半平面相交. #include<cstdio> #include<cmath> ...
- leetcode@ [139/140] Word Break & Word Break II
https://leetcode.com/problems/word-break/ Given a string s and a dictionary of words dict, determine ...
- HDU-4662 MU Puzzle 水题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4662 倒推考虑长度就可以了. //STATUS:C++_AC_31MS_240KB #include ...
- git http方式时保存密码
一直使用ssh方式,但是git@osc的ssh只能pull,不能push - -||| htts方式保存密码老是忘记,每次提交代码都要输入密码烦死了.找到文章备忘: 转自:http://git ...
- Java网络编程(URL&URLConnection)
package cn.itcast.net.p2.ie_server; import java.io.IOException; import java.io.InputStream; import j ...
- A Tour of Go Methods
Go does not have classes. However, you can define methods on struct types. The method receiver appea ...
- unigui多页签UI框架
procedure TMainForm.openForm(Caption, FormClassName: string);var i: integer; sheet: TUniTabSheet;beg ...
- position绝对剧中
function loginH(){ var loginH = $('.sign-main-bg .sign-main-content'); var h = loginH.height(); logi ...
- win10 64位安装mysql
原文地址:http://blog.csdn.net/kingyumao/article/details/51925795
- Java循环语句 while
特点:先判断,后执行 如: public class HelloWorld { public static void main(String[] args) { int i = 1; // 代表 1 ...