首页 技术 正文
技术 2022年11月16日
0 收藏 868 点赞 3,855 浏览 9213 个字

下载链接地址:https://share.weiyun.com/9ac3ca3fb29648bb1aad1b83a76b123c (密码:4y9t)【含mini版】

欢迎使用leonaScroll-1.3.js,如您在使用过程中发现更多问题,欢迎指正! 
介绍:是一款基于jquery框架实现的自定义竖向自适应滚动条。插件大小:leonaScroll-1.2 .js         10.2KB              leonaScroll-min-1.2.js    6.39KB 更新:1.3版本 
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  滚动文本类名

  1. 默认:该方法选中元素的第一个子元素,并默认给其添加一个名为“scroll_text”class类名
  2. 解释:可自定义你需要滚动的文本类名,默认为调用方法下的第一个子元素,填写滚动文本类名即可,规则和css一样,如.class或#id或li
  3. 用法:$(“Element”).LeonaScroll({scroll_text :’.class’})

speed  滚动速度

  1. 默认:20px
  2. 解释:可自定义调节滚动的快慢,以像素定义,数字越大越快,越小越慢
  3. 用法:$(“Element”).LeonaScroll({speed:50})

sWidth 滚动条宽度

  1. 默认:14px
  2. 解释:可自定义滚动条整体宽度,以像素为单位,填入数字即可
  3. 用法:$(“Element”).LeonaScroll({sWidth :14})

updownH 微调按钮高度

  1. 默认:20
  2. 解释:可自定义滚动条上下箭头(微调按钮)高度,其宽度会根据滚动条宽度自适应,你只需定义好滚动条宽度即可
  3. 用法:$(“Element”).LeonaScroll({updownH :20})

text_width 滚动文本内容宽度

  1. 默认:滚动文本内容宽度=调用方法时选中的对象宽度-滚动条宽度
  2. 解释:如果你希望的滚动条与滚动文本之间有一定间隔,你可以自定义滚动文本的内容的宽度,这里的滚动文本定位采用的float:right; 滚动条采用float:left,以像素为单位,填写数字即可
  3. 用法:$(“Element”).LeonaScroll({text_width :400})

scrollbar 未超出时滚动条显示否

  1. 默认:true
  2. 解释:滚动文本未超出可显示区域时,滚动条是否显示,显示为false,不显示为true
  3. 用法:$(“Element”).LeonaScroll({scrollbar :20})

addHeight 动态输出修复高度

  1. 默认:0px
  2. 解释:文本内容实际高度增加(加高),此属性是为了解决部分因动态数据加载慢于滚动条插件加载时,导致插件无法获取到准确的可显示文本高度,从而造成显示文本内容丢失。该属性可以硬性给可显示文本增加高度。
  3. 用法:$(“Element”).LeonaScroll({addHeight :40})

autoStyle 默认美化样式

  1. 默认:true
  2. 解释:是否需要默认的美化样式,需要为true,不需要为false,如不需要则需要自定义美化样式,因此,该属性要和美化样式属性搭配使用,不能单独使用,否则会出现乱码,小白慎用,大神随意
  3. 用法:$(“Element”).LeonaScroll({autoStyle :false})

美化样式属性

  • 类型:autoStyle属性值为true是需要,为false则是必须
  • 默认:黑色样式,如图:
  • jquery-leonaScroll-1.3-自定义竖向自适应滚动条插件
  • 属性说明:
    1. scroll_UDCss:滚动条的上下微调按钮样式
    2. scroll_upCss:滚动条的上微调按钮样式
    3. scroll_upCssHover:滚动条的上微调按钮鼠标悬停样式
    4. scroll_downCss:滚动条的下微调按钮样式
    5. scroll_downCssHover:滚动条的下微调按钮鼠标悬停样式
    6. scroll_cenCss:滚动条中间轨道样式
    7. scroll_cenButtonCss:滚动条中间滑动按钮样式
  • 样式使用举例:
    1. autoStyle: false,
    2. scroll_UDCss: “background-image: url(img/bw.png); background-repeat: no-repeat;”,
    3. scroll_upCss: “background-position: center 6px; border-radius: 5px 5px 0 0;”,
    4. scroll_upCssHover: “background-position: center -11px;”,
    5. scroll_downCss: “background-position: center -49px; border-radius: 0 0 5px 5px;”,
    6. scroll_downCssHover: “background-position: center -31px;”,
    7. scroll_cenCss: “”,
    8. scroll_cenButtonCss: “background: url(img/tiao.jpg) repeat-y 0 0; border-radius: 5px;”
  • 图示说明:
  • jquery-leonaScroll-1.3-自定义竖向自适应滚动条插件

插件代码:

 $.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

原文链接:http://www.cnblogs.com/leona-d/p/5950280.html

版权声明:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,085
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,560
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,409
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,182
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,819
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,902