animateBackground-plugin
2024-10-19 00:31:19
(function ($) {
if (!document.defaultView || !document.defaultView.getComputedStyle) {
var oldCurCSS = jQuery.curCSS;
jQuery.curCSS = function (elem, name, force) {
if (name === 'background-position') {
name = 'backgroundPosition';
}
if (name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[name]) {
return oldCurCSS.apply(this, arguments);
}
var style = elem.style;
if (!force && style && style[name]) {
return style[name];
}
return oldCurCSS(elem, 'backgroundPositionX', force) + ' ' + oldCurCSS(elem, 'backgroundPositionY', force);
};
} var oldAnim = $.fn.animate;
$.fn.animate = function (prop) {
if ('background-position' in prop) {
prop.backgroundPosition = prop['background-position'];
delete prop['background-position'];
}
if ('backgroundPosition' in prop) {
prop.backgroundPosition = '(' + prop.backgroundPosition + ')';
}
return oldAnim.apply(this, arguments);
}; function toArray(strg) {
strg = strg.replace(/left|top/g, '0px');
strg = strg.replace(/right|bottom/g, '100%');
strg = strg.replace(/([-\.]+)(\s|\)|$)/g, "$1px$2");
var res = strg.match(/(-?[-\.]+)(px|\%|em|pt)\s(-?[-\.]+)(px|\%|em|pt)/);
return [parseFloat(res[], ), res[], parseFloat(res[], ), res[]];
} $.fx.step.backgroundPosition = function (fx) {
if (!fx.bgPosReady) {
var start = $.curCSS(fx.elem, 'backgroundPosition'); if (!start) {//FF2 no inline-style fallback
start = '0px 0px';
} start = toArray(start); fx.start = [start[], start[]]; var end = toArray(fx.end);
fx.end = [end[], end[]]; fx.unit = [end[], end[]];
fx.bgPosReady = true;
} var nowPosX = [];
nowPosX[] = ((fx.end[] - fx.start[]) * fx.pos) + fx.start[] + fx.unit[];
nowPosX[] = ((fx.end[] - fx.start[]) * fx.pos) + fx.start[] + fx.unit[];
fx.elem.style.backgroundPosition = nowPosX[] + ' ' + nowPosX[];
};
})(jQuery);
调用示例:
//动画调用示例
$("#viewBody").animate({ backgroundPosition: '(520px 0)' });
最新文章
- 事件EVENT与waitforsingleobject的使用
- 【原】Github系列之三:开源iOS下 渐变颜色的进度条WGradientProgress
- C#-WinForm-用户控件如何获取父级窗体
- 探索javascript----this的指向问题
- BI先特技软件 Analyzer安装时的部分问题
- MSBI BigData demo—sqoop import
- tomcat server获取用户的请求地址
- Java GC 专家系列3:GC调优实践
- 使用ICE进程间通信时,IP和端口的选择
- CSS的display、hover、overflow、&;copy(版权符号)、borer-radius(边框圆角)
- 【Java 它 JVM】对象的创建过程
- 如何用Python在豆瓣中获取自己喜欢的TOP N电影信息
- Flex设置LinkButton的背景色
- macOS卸载应用不彻底
- kali linux 使用笔记本快捷键调节音量
- mongooDb链接javaapi
- 弹出框sweetalert插件的简单使用
- [Aaronyang] 写给自己的WPF4.5 笔记8[复杂数据处理三步曲,数据视图精讲1/3]
- Chrome Extension 实战
- 【转】在SpringMVC Controller中注入Request成员域
热门文章
- (1)ansible基本配置
- Druid 架构
- 【ASP.NET】必须知道的ASP.NET核心处理
- Codeforces 429 B. Working out-dp( Codeforces Round #245 (Div. 1))
- 【数据结构】 最小生成树(二)——kruskal算法
- python 字符串,数学之间的不可描述的关系
- START法则
- 「HNOI2013」游走
- BZOJ 2152 聪聪可可(点分治)
- 【动态规划】【滚动数组】【bitset】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem J. Terminal