jquery-leonaScroll-1.3-自定义竖向自适应滚动条插件
下载链接地址:https://share.weiyun.com/9ac3ca3fb29648bb1aad1b83a76b123c (密码:4y9t)【含mini版】
介绍:是一款基于jquery框架实现的自定义竖向自适应滚动条。
1、滚动文本未超出可显示区域时,滚动条button显示不正常问题
2、脱离了原来的mousewheel插件,仅基于jq
3、更正了用法介绍文字错误
1、建立好您的Html,引用jquery框架、leonaScroll-1.3.js插件
<script src="js/jquery-1.10.2.js" type="text/javascript"></script>
<script src="js/leonaScroll-source-1.2.js"></script>
2、使用$("Element").LeonaScroll()调用插件
3、属性使用说明:
**多个属性之间用“ , ”分隔
**属性值需要“{ }”括起来
**属性默认有值,全部为可选,可根据需求设置合适的属性,以符合您的页面需求
**即$("Element").LeonaScroll({属性名:属性值,属性名:属性值})
leonaScroll-1.3.js——属性
- 默认:该方法选中元素的第一个子元素,并默认给其添加一个名为“scroll_text”class类名
- 解释:可自定义你需要滚动的文本类名,默认为调用方法下的第一个子元素,填写滚动文本类名即可,规则和css一样,如.class或#id或li
- 用法:$("Element").LeonaScroll({scroll_text :'.class'})
- 默认:20px
- 解释:可自定义调节滚动的快慢,以像素定义,数字越大越快,越小越慢
- 用法:$("Element").LeonaScroll({speed:50})
- 默认:14px
- 解释:可自定义滚动条整体宽度,以像素为单位,填入数字即可
- 用法:$("Element").LeonaScroll({sWidth :14})
- 默认:20
- 解释:可自定义滚动条上下箭头(微调按钮)高度,其宽度会根据滚动条宽度自适应,你只需定义好滚动条宽度即可
- 用法:$("Element").LeonaScroll({updownH :20})
- 默认:滚动文本内容宽度=调用方法时选中的对象宽度-滚动条宽度
- 解释:如果你希望的滚动条与滚动文本之间有一定间隔,你可以自定义滚动文本的内容的宽度,这里的滚动文本定位采用的float:right; 滚动条采用float:left,以像素为单位,填写数字即可
- 用法:$("Element").LeonaScroll({text_width :400})
- 默认:true
- 解释:滚动文本未超出可显示区域时,滚动条是否显示,显示为false,不显示为true
- 用法:$("Element").LeonaScroll({scrollbar :20})
- 默认:0px
- 解释:文本内容实际高度增加(加高),此属性是为了解决部分因动态数据加载慢于滚动条插件加载时,导致插件无法获取到准确的可显示文本高度,从而造成显示文本内容丢失。该属性可以硬性给可显示文本增加高度。
- 用法:$("Element").LeonaScroll({addHeight :40})
- 默认:true
- 解释:是否需要默认的美化样式,需要为true,不需要为false,如不需要则需要自定义美化样式,因此,该属性要和美化样式属性搭配使用,不能单独使用,否则会出现乱码,小白慎用,大神随意
- 用法:$("Element").LeonaScroll({autoStyle :false})
- 类型:autoStyle属性值为true是需要,为false则是必须
- 默认:黑色样式,如图:

- 属性说明:
- scroll_UDCss:滚动条的上下微调按钮样式
- scroll_upCss:滚动条的上微调按钮样式
- scroll_upCssHover:滚动条的上微调按钮鼠标悬停样式
- scroll_downCss:滚动条的下微调按钮样式
- scroll_downCssHover:滚动条的下微调按钮鼠标悬停样式
- scroll_cenCss:滚动条中间轨道样式
- scroll_cenButtonCss:滚动条中间滑动按钮样式
- 样式使用举例:
- autoStyle: false,
- scroll_UDCss: "background-image: url(img/bw.png); background-repeat: no-repeat;",
- scroll_upCss: "background-position: center 6px; border-radius: 5px 5px 0 0;",
- scroll_upCssHover: "background-position: center -11px;",
- scroll_downCss: "background-position: center -49px; border-radius: 0 0 5px 5px;",
- scroll_downCssHover: "background-position: center -31px;",
- scroll_cenCss: "",
- scroll_cenButtonCss: "background: url(img/tiao.jpg) repeat-y 0 0; border-radius: 5px;"
- 图示说明:

插件代码:
$.fn.extend({
LeonaScroll: function (parameter) {
parameter = parameter === undefined ? {} : parameter;
var Sname = $(this).selector;
var allar = this;
return this.each(function () {
var havedefsrolltext = $(this).find(parameter.scroll_text).length;
if (!havedefsrolltext) {
parameter.scroll_text = ".scroll_text";
$($(this).children().get(0)).addClass("scroll_text");
}
//变量声明
var elem = $(this),
celem = $(this).find(parameter.scroll_text),
index = Sname.replace(".", "").toUpperCase() + $(Sname).index($(this)),
text_hidden = $(elem).height(),
con_width = $(elem).width();
$(elem).unbind();
//添加滚动条Html
var cansc = $(".leonaup" + index + "").length;
if (!cansc) {
var scrollHTML = "";
scrollHTML += "<div class='scroll_up leonaup" + index + "'></div>";
scrollHTML += "<div class='scroll_cen leonacen" + index + "'><div class='scroll_button leonabutton" + index + "'></div></div>";
scrollHTML += "<div class='scroll_down leonadown" + index + "'></div>";
$(elem).append("<div class='scroll leonas" + index + "'> " + scrollHTML + "</div>");
}
//滚动条CSS--必要
var sW = parameter.sWidth === undefined ? 14 : parameter.sWidth;
var scrollStyle = Sname + "{ position: relative; overflow-y: hidden; clear:none;-moz-user-select: none; /*火狐*/ -webkit-user-select: none; /*webkit浏览器*/ -ms-user-select: none; /*IE10*/ -khtml-user-select: none; /*早期浏览器*/ user-select: none; }\r\n";
scrollStyle += Sname + " " + parameter.scroll_text + "{width:" + (parameter.text_width === undefined ? (con_width - sW) : parameter.text_width) + "px; word-break: break-word; position: absolute; left: 0; top: 0; clear:both; }\r\n";
scrollStyle += Sname + " .scroll { height:" + text_hidden + "px; float:right; }\r\n";
scrollStyle += Sname + " .scroll," + Sname + " .scroll .scroll_cen, " + Sname + " .scroll .scroll_up, " + Sname + " .scroll .scroll_down { width:" + sW + "px; }\r\n"
scrollStyle += Sname + " .scroll .scroll_up," + Sname + " .scroll .scroll_down {height:" + (parameter.updownH === undefined ? 20 : parameter.updownH) + "px; cursor: pointer;}\r\n";
scrollStyle += Sname + " .scroll .scroll_cen { height:" + (text_hidden - (parameter.updownH === undefined ? 20 : parameter.updownH) * 2) + "px; position: relative; }\r\n";
scrollStyle += Sname + " .scroll .scroll_cen .scroll_button { width:" + (sW - 2) + "px; margin: 0px 1px; position: absolute; cursor: pointer; }\r\n";
//滚动条美化CSS--默认
var needAutoStyle = parameter.autoStyle === undefined ? true : parameter.autoStyle
if (needAutoStyle == true) {
scrollStyle += Sname + " .scroll .scroll_up, .scroll .scroll_down { background-image: url(/images/bw.png); background-color: #161515; background-repeat: no-repeat; }\r\n";
scrollStyle += Sname + " .scroll .scroll_up { background-position: center 6px; border-radius: 5px 5px 0 0;} \r\n ";
scrollStyle += Sname + " .scroll .scroll_up:hover { background-position: center -11px;} \r\n";
scrollStyle += Sname + " .scroll .scroll_down { background-position: center -49px; border-radius: 0 0 5px 5px;} \r\n";
scrollStyle += Sname + " .scroll .scroll_down:hover { background-position: center -31px;}\r\n ";
scrollStyle += Sname + " .scroll .scroll_cen { background-color: #777676;}\r\n ";
scrollStyle += Sname + " .scroll .scroll_cen .scroll_button { background: url(/images/tiao.jpg) repeat-y 0 0; border-radius: 5px;}\r\n ";
} else {
scrollStyle += Sname + " .scroll .scroll_up, .scroll .scroll_down {" + parameter.scroll_UDCss + "}\r\n";
scrollStyle += Sname + " .scroll .scroll_up {" + parameter.scroll_upCss + "}\r\n ";
scrollStyle += Sname + " .scroll .scroll_up:hover {" + parameter.scroll_upCssHover + "}\r\n";
scrollStyle += Sname + " .scroll .scroll_down { " + parameter.scroll_downCss + "}\r\n";
scrollStyle += Sname + " .scroll .scroll_down:hover {" + parameter.scroll_downCssHover + "}\r\n ";
scrollStyle += Sname + " .scroll .scroll_cen {" + parameter.scroll_cenCss + "}\r\n ";
scrollStyle += Sname + " .scroll .scroll_cen .scroll_button { " + parameter.scroll_cenButtonCss + "}\r\n ";
}
//添加上述样式至html头部head中
if ($("#leonascrollStyle").length) {
$("#leonascrollStyle").html($("#leonascrollStyle").html() + scrollStyle);
} else {
$("head").append("<style type='text/css' id='leonascrollStyle'>" + scrollStyle + "</style>");
}
//变量声明
var text_show = parameter.addHeight === undefined ? $(celem).height() : $(celem).height() + parameter.addHeight,
scroll_b = $(".leonabutton" + index + ""),
text_p = text_hidden / text_show,
bH_max = $(".leonas" + index + " .leonacen" + index + "").height(),
bH = text_p * bH_max;
if (parameter.scrollbar == true || parameter.scrollbar === undefined) {
if (text_p >= 1) {
$(".leonas" + index + "").css("display", "none")
}
else {
$(".leonas" + index + "").css("display", "block"); scroll_b.css("height", bH + "px");
};
} else if (parameter.scrollbar == false) {
if (text_p >= 1) {
$(".leonas" + index + "").css("display", "block"); scroll_b.css("height", bH_max + "px");
bH = bH_max;
return false;
}
else {
$(".leonas" + index + "").css("display", "block"); scroll_b.css("height", bH + "px");
};
};
//鼠标拖动div事件
var needMove = false, mouseY = 0;
scroll_b.mousedown(function (event) { needMove = true; var bH_Top = scroll_b.position().top; mouseY = event.pageY - bH_Top; });
$(document).mouseup(function (event) { needMove = false; });
$(document).mousemove(function (event) {
if (needMove) {
var sMouseY = event.pageY, bH_Top = sMouseY - mouseY, textY = bH_Top / bH_max * text_show;
if (bH_Top <= 0) {
scroll_b.css("top", 0);
$(celem).css("top", 0);
return;
}
if (bH_Top >= bH_max - bH) {
scroll_b.css("top", bH_max - bH);
$(celem).css("top", text_hidden - text_show);
return;
}
scroll_b.css("top", bH_Top); $(celem).css("top", -textY);
}
return;
});
//定义上下滚动规则
function goGun(direction, timer) {
bH_Top = scroll_b.position().top;
var h = 0; h += (parameter.speed === undefined ? 20 : parameter.speed);
if (direction == 1) {
var Toping = bH_Top - h;
if (bH_Top <= 0 || Toping <= 0) {
scroll_b.css("top", 0);
$(celem).css("top", 0);
if (timer == 2) clearInterval(goThread);
return;
}
scroll_b.css("top", bH_Top - h);
}
if (direction == -1) {
var Downing = bH_Top + h;
if (bH_Top >= bH_max - bH || Downing >= bH_max - bH) {
scroll_b.css("top", bH_max - bH);
$(celem).css("top", text_hidden - text_show);
if (timer == 2) clearInterval(goThread);
return;
}
scroll_b.css("top", bH_Top + h);
}
var textY = bH_Top / bH_max * text_show;
$(celem).css("top", -textY);
}
//上下微调按钮事件
function minTiao(minTB, d, t) {
var goThread = "";
minTB.mouseup(function () { clearInterval(goThread); });
minTB.mousedown(function () {
clearInterval(goThread);
goThread = setInterval(function () { goGun(d, t); }, 300);
});
minTB.click(function () { goGun(d); });
}
minTiao($(".leonaup" + index + ""), 1, 2);
minTiao($(".leonadown" + index + ""), -1, 2);
//判断鼠标上下滚动方向
var delta;
var scrollFunc = function (e) {
e = e || window.event;
if (e.wheelDelta) {
if (e.wheelDelta > 0) { delta = 1 }
if (e.wheelDelta < 0) { delta = -1 }
} else if (e.detail) {
if (e.detail > 0) { delta = 1 }
if (e.detail < 0) { delta = -1 }
};
//滚轮事件
if (text_p < 1) {
if (cansc <= 1) {
if (delta == 1) {//up
goGun(1, 0);
if (scroll_b.position().top != 0)return false;
} if (delta == -1) {//down
goGun(-1, 0);
if (Math.ceil(scroll_b.position().top) != Math.ceil(bH_max - bH))return false;
}
}
};
}
//当鼠标悬停在元素上的时候给页面绑定滚动事件
$(elem).hover(function () {
if (document.addEventListener) {
document.addEventListener('DOMMouseScroll', scrollFunc, false);
}
window.onmousewheel = document.onmousewheel = scrollFunc;
}, function () {//否则解绑滚动事件
if (document.addEventListener) {
document.removeEventListener('DOMMouseScroll', scrollFunc, false);
}
window.onmousewheel = document.onmousewheel = null;
});
});
}
});
作者:leona
jquery-leonaScroll-1.3-自定义竖向自适应滚动条插件的更多相关文章
- 自定义基于jquery竖向瀑布流插件
公司新项目做了一个关于图片的板块,网上找了一些瀑布流插件都不是很适合自己,于是就自己造轮子写一个,并封装成插件github 于是就想分享一下,主要是为了更好的学习与记忆. 如果大家进来了,希望能给我g ...
- 15个带示例的jQuery滚动条插件
1.NiceScroll:可用于桌面.移动与触摸设备的jQuery滚动插件 NiceScroll是一个jQuery插件(since 1.5),它有着类似于ios/移动设备的样式.它支持Div.iFra ...
- JS - 兼容到ie7的自定义样式的滚动条封装
demo: html: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...
- 常用样式制作思路 自定义按钮~自适应布局~常见bug seajs简记 初学者必知的HTML规范 不容忽略的——CSS规范
常用样式制作思路 学习常用样式总结参考来自这里 带点文字链接列表利用:before实现 1 <!DOCTYPE html> 2 <html lang="en" ...
- Adaptive Backgrounds – jQuery 自适应背景插件
Adaptive Backgrounds 是一款很特别的 jQuery 插件,可以从图像中提取主导颜色并将它应用到它的父元素.这个插件利用 Canvas 元素和 ImageData 对象.需要注意的是 ...
- 11 个最佳 jQuery 滚动条插件
通过jQuery滚动条插件,你可以换掉千篇一律的默认浏览器滚动条,让你的网站或web项目更具特色,更有吸引力.本文收集了11款非常漂亮.实用的jQuery滚动条插件,你可以轻松将它们应用在自己的网站中 ...
- 原创新闻 11 个最佳 jQuery 滚动条插件
通过jQuery滚动条插件,你可以换掉千篇一律的默认浏览器滚动条,让你的网站或web项目更具特色,更有吸引力.本文收集了11款非常漂亮.实用的jQuery滚动条插件,你可以轻松将它们应用在自己的网站中 ...
- 网站开发常用jQuery插件总结(五)滚动条插件nanoscroller
网站在展示信息时,如果信息量过大,解决方法主要有三种.1.分页,将信息分页显示.2.整页显示,但是页面过长,影响浏览体验.3.使用滚动条,而默认滚动条样式太单一,用户体验不友好.所以我们需要美化滚动条 ...
- jQuery滚动条插件 – jquery.slimscroll.js
jquery.slimscroll.js插件是一个支持把内容放在一个盒子里面,固定一个高度,超出的则使用滚动.jquery.slimscroll.js不仅可以定义高度.宽度,还可以定义位置.滚动条大小 ...
随机推荐
- C# - 网络编程 之 TcpClient与TcpListener
TcpClient类 TcpListener类 TCP通信 UDP通信 参考:
- gRPC源码分析2-Server的建立
gRPC中,Server.Client共享的Class不是很多,所以我们可以单独的分别讲解Server和Client的源码. 通过第一篇,我们知道对于gRPC来说,建立Server是非常简单的,还记得 ...
- JDBC介绍
1.DriverManager用来建立和数据库的链接以及管理JDBC驱动程序 driverManager的常用方法 方法 描述 registerDriver(Driver driver) 在Derve ...
- 金融行业的BI应用分析
商业智能是一种提高企业智能化的手段,它可以满足企业发展的需要.提高企业的竞争力.同时,对于提高金融行业的风险管理.提升对外服务的质量都能够起到关键性的作用. 在市场竞争和银行业务转型期间,商业智能对于 ...
- View and Data API Tips: Constrain Viewer Within a div Container
By Daniel Du When working with View and Data API, you probably want to contain viewer into a <div ...
- Unicode简介
计算机只能处理二进制,因此需要把文字表示为二进制才能被计算机理解和识别. 一般的做法是为每一个字母或汉字分配一个id,然后用二进制表示这个id,存在内存或磁盘中.计算机可以根据二进制数据知道这个id是 ...
- 高仿ios版美团框架项目源码
高仿美团框架基本已搭好.代码简单易懂,适合新人.适合新人.新人. <ignore_js_op> 源码你可以到ios教程网那里下载吧,这里我就不上传了,http://ios.662p ...
- (十五)使用Nexus创建Maven私服
通过建立自己的私服,就可以降低中央仓库负荷.节省外网宽带.加速Maven构建.自己部署构件等,从而高效的使用Maven.有三种专门的Maven仓库管理软件可以用来帮助大家建立私服:Apache基金会的 ...
- 学习Maven之Maven Clean Plugin
1.maven-clean-plugin是个什么鬼? maven-clean-plugin这个插件用maven的人都不陌生.我们在执行命令mvn clean时调用的就是这个插件. 这个插件的主要作用就 ...
- java中使用mongodb的几种方式
最近有时间看了一下mongodb,因为mongodb更容易扩展所以考虑使用mongodb来保存数据. 首先下载安装mongodb,这是很简单的,装好后使用mongod命令就可以启动数据库.正式部署的话 ...