可视区域检测js
2016-04-12 11:31
471 查看
/******************************
e7详情
2016-03-17 18:50:15 liuqiao 创建
*******************************/
$namespace("iuni.official_e7_detail");
/******************************
全局参数配置
*******************************/
iuni.official_e7_detail.data = {
};
iuni.official_e7_detail.dom = {
container: document.getElementById('container')
};
/******************************
初始化配置
*******************************/
iuni.official_e7_detail.init = function() {
this.scrollY();
this.sliderBanner();
};
//l轮播动画
iuni.official_e7_detail.sliderBanner = function() {
$(this.dom.container).find('.slider .banner').flexslider({
animation: "slide", //String: Select your animation type, "fade" or "slide"图片变换方式:淡入淡出或者滑动
slideshowSpeed: 7000, //图片切换速度
slideDirection: "horizontal", //String: Select the sliding direction, "horizontal" or "vertical"图片设置为滑动式时的滑动方向:左右或者上下
animationSpeed: 2000, //单张图片动画速度
directionNav: false,
animationLoop: true,
pauseOnHover: true,
slideToStart: 0
});
};
/**
* 上下滚动
*/
iuni.official_e7_detail.scrollY = function() {
var me = this;
var docElem = window.document.documentElement;
function getViewportH() {
var client = docElem['clientHeight'],
inner = window['innerHeight'];
if (client < inner)
return inner;
else
return client;
}
function scrollY() {
return window.pageYOffset || docElem.scrollTop;
}
function getOffset(el) {
var offsetTop = 0,
offsetLeft = 0;
do {
if (!isNaN(el.offsetTop)) {
offsetTop += el.offsetTop;
}
if (!isNaN(el.offsetLeft)) {
offsetLeft += el.offsetLeft;
}
} while (el = el.offsetParent)
return {
top: offsetTop,
left: offsetLeft
}
}
function inViewport(el, h) {
var elH = el.offsetHeight,
scrolled = scrollY(),
viewed = scrolled + getViewportH(),
elTop = getOffset(el).top,
elBottom = elTop + elH,
h = h || 0;
return (elTop + elH * h) <= viewed && (elBottom) >= scrolled;
}
$(window).on('scroll', function() {
var top = $(this).scrollTop(),
h = $(this).height();
// var i = top / h * 100;
// var j = 1 - i;
$(me.dom.container).find('.mobile').each(function() {
if (inViewport(this)) {
var top = this.getBoundingClientRect().top;
var i = top / h * 200;
this.style.cssText = 'transition: all 2s ease-in-out; transform:translate3d(0px, ' + i + 'px, 0px) rotate(0deg)'
} else {
this.style.cssText = '';
}
});
$(me.dom.container).find('.mobile1').each(function() {
if (inViewport(this)) {
var top = this.getBoundingClientRect().top,
i;
if (top < 0) {
i = -(top / h * 1000);
} else {
i = top / h * 200;
}
this.style.cssText = 'transition: all 2s ease-in-out; transform:translate3d(0px, ' + i + 'px, 0px) rotate(0deg)'
} else {
this.style.cssText = '';
}
});
$(me.dom.container).find('.mobile2').each(function() {
if (inViewport(this)) {
var top = this.getBoundingClientRect().top;
var i = top / h * 200;
var j = top / h * 30;
this.style.cssText = 'transition: all 2s ease-in-out; transform:translate3d(0px, ' + i + 'px, 0px) rotate(' + j + 'deg)'
} else {
this.style.cssText = '';
}
});
$(me.dom.container).find('.interface').each(function() {
if (inViewport(this)) {
this.style.cssText = 'transition: all 2s ease-in-out; transform:translate3d(-3.8%, -5.2%, 0px) rotate(3deg)';
// transition: all 2s ease-in-out;
//transform: translate3d(-50px,-40px, 0px) rotateX(0deg);
} else {
this.style.cssText = '';
}
})
})
};
/******************************
功能实现区
*******************************/
iuni.official_e7_detail.init();
e7详情
2016-03-17 18:50:15 liuqiao 创建
*******************************/
$namespace("iuni.official_e7_detail");
/******************************
全局参数配置
*******************************/
iuni.official_e7_detail.data = {
};
iuni.official_e7_detail.dom = {
container: document.getElementById('container')
};
/******************************
初始化配置
*******************************/
iuni.official_e7_detail.init = function() {
this.scrollY();
this.sliderBanner();
};
//l轮播动画
iuni.official_e7_detail.sliderBanner = function() {
$(this.dom.container).find('.slider .banner').flexslider({
animation: "slide", //String: Select your animation type, "fade" or "slide"图片变换方式:淡入淡出或者滑动
slideshowSpeed: 7000, //图片切换速度
slideDirection: "horizontal", //String: Select the sliding direction, "horizontal" or "vertical"图片设置为滑动式时的滑动方向:左右或者上下
animationSpeed: 2000, //单张图片动画速度
directionNav: false,
animationLoop: true,
pauseOnHover: true,
slideToStart: 0
});
};
/**
* 上下滚动
*/
iuni.official_e7_detail.scrollY = function() {
var me = this;
var docElem = window.document.documentElement;
function getViewportH() {
var client = docElem['clientHeight'],
inner = window['innerHeight'];
if (client < inner)
return inner;
else
return client;
}
function scrollY() {
return window.pageYOffset || docElem.scrollTop;
}
function getOffset(el) {
var offsetTop = 0,
offsetLeft = 0;
do {
if (!isNaN(el.offsetTop)) {
offsetTop += el.offsetTop;
}
if (!isNaN(el.offsetLeft)) {
offsetLeft += el.offsetLeft;
}
} while (el = el.offsetParent)
return {
top: offsetTop,
left: offsetLeft
}
}
function inViewport(el, h) {
var elH = el.offsetHeight,
scrolled = scrollY(),
viewed = scrolled + getViewportH(),
elTop = getOffset(el).top,
elBottom = elTop + elH,
h = h || 0;
return (elTop + elH * h) <= viewed && (elBottom) >= scrolled;
}
$(window).on('scroll', function() {
var top = $(this).scrollTop(),
h = $(this).height();
// var i = top / h * 100;
// var j = 1 - i;
$(me.dom.container).find('.mobile').each(function() {
if (inViewport(this)) {
var top = this.getBoundingClientRect().top;
var i = top / h * 200;
this.style.cssText = 'transition: all 2s ease-in-out; transform:translate3d(0px, ' + i + 'px, 0px) rotate(0deg)'
} else {
this.style.cssText = '';
}
});
$(me.dom.container).find('.mobile1').each(function() {
if (inViewport(this)) {
var top = this.getBoundingClientRect().top,
i;
if (top < 0) {
i = -(top / h * 1000);
} else {
i = top / h * 200;
}
this.style.cssText = 'transition: all 2s ease-in-out; transform:translate3d(0px, ' + i + 'px, 0px) rotate(0deg)'
} else {
this.style.cssText = '';
}
});
$(me.dom.container).find('.mobile2').each(function() {
if (inViewport(this)) {
var top = this.getBoundingClientRect().top;
var i = top / h * 200;
var j = top / h * 30;
this.style.cssText = 'transition: all 2s ease-in-out; transform:translate3d(0px, ' + i + 'px, 0px) rotate(' + j + 'deg)'
} else {
this.style.cssText = '';
}
});
$(me.dom.container).find('.interface').each(function() {
if (inViewport(this)) {
this.style.cssText = 'transition: all 2s ease-in-out; transform:translate3d(-3.8%, -5.2%, 0px) rotate(3deg)';
// transition: all 2s ease-in-out;
//transform: translate3d(-50px,-40px, 0px) rotateX(0deg);
} else {
this.style.cssText = '';
}
})
})
};
/******************************
功能实现区
*******************************/
iuni.official_e7_detail.init();
相关文章推荐
- 【bzoj1449】【JSOI2009】【球队收益】【费用流】
- 介绍一篇关于session的好文章,写的很详细(jsp-servlet 技术)
- js跨域问题
- 20款最好的JavaScript开发框架
- js日期加减
- 对象与json文件之间的转换
- slide.js使用文档
- 前台post提交表单时获取不到数据的原因
- eclipse项目里javascript总是验证,且出现最多的error是 "Description Resource Path Location Type Syntax error on toke
- js一百零一夜之第十四夜-正则表达式(1)
- JSON
- agent_web--common.jsp
- JayRock:JSON and JSON_RPC for .Net
- 笔记练习:《Javascript入门经典(第5版)》page185_15.10_Practice
- javascript设计模式--简单工厂模式
- Js Map 和 List的简单实现
- JS数组
- 【Javascript】js图形编辑器库介绍
- js实现右键菜单的一个实例
- Js中的4个事件