图片轮播特效,jQuery实现
2016-11-24 19:41
597 查看
img 中的alt属性作用:当img图片无法显示时,将显示alt中的文字。<span>中index的作用:给这个元素添加一个属性,按照这个属性值给元素排序
jQuery实现
javascript实现特效:
var $ = function(id){
return document.getElementById(id);
}
var addEvent = function(obj,event,fn){
if(obj.addEventListener){
obj.addEventListener(event,fn,false);
}else if(obj.attachEvent){
obj.attachEvent('on'+event,fn);
}
}
var domSider = $('J_BdSide');
var scrollEvent = function(){
var sideHeight = domSider.offsetHeight;
var screenHeight =document.documentElement.clientHeight||document.body.clientHeight;
var scrollHeight = document.documentElement.scrollTop||document.body.scrollTop;
if(scrollHeight+screenHeight>sideHeight){
domSider.style.cssText = 'position:fixed;right:0px;top:'+(-(sideHeight-screenHeight))+'px';
}else{
domSider.style.position='static';
}
}
addEvent(window,'scroll',function(){
scrollEvent();
});
addEvent(window,'resize',function(){
scrollEvent();
});
jQuery实现
$(window).scroll(function() { // 固定边栏滚动特效 var windowHeight = $(window).scrollTop() + $(window).height(); var sideHeight = $('#J_BdSide').height(); if (windowHeight > sideHeight) { $('#J_BdSide').css({ 'position' : 'fixed', right : '0px', top : -(sideHeight - $(window).height()) }); } else { $('#J_BdSide').css({ 'position' : 'static' }); } });
javascript实现特效:
var $ = function(id){
return document.getElementById(id);
}
var addEvent = function(obj,event,fn){
if(obj.addEventListener){
obj.addEventListener(event,fn,false);
}else if(obj.attachEvent){
obj.attachEvent('on'+event,fn);
}
}
var domSider = $('J_BdSide');
var scrollEvent = function(){
var sideHeight = domSider.offsetHeight;
var screenHeight =document.documentElement.clientHeight||document.body.clientHeight;
var scrollHeight = document.documentElement.scrollTop||document.body.scrollTop;
if(scrollHeight+screenHeight>sideHeight){
domSider.style.cssText = 'position:fixed;right:0px;top:'+(-(sideHeight-screenHeight))+'px';
}else{
domSider.style.position='static';
}
}
addEvent(window,'scroll',function(){
scrollEvent();
});
addEvent(window,'resize',function(){
scrollEvent();
});
相关文章推荐
- jQuery实现图片轮播特效代码分享
- jQuery手动点击实现图片轮播特效
- 原生js和jquery实现图片轮播特效
- 基于jquery实现的仿优酷图片轮播特效代码
- jquery实现横向图片轮播特效代码分享
- 分享jquery实现百叶窗特效的图片轮播
- jQuery实现友好的轮播图片特效
- 原生js和jquery实现图片轮播特效
- jQuery插件boxScroll实现图片轮播特效
- 基于jQuery实现响应式圆形图片轮播特效
- jQuery手动点击实现图片轮播特效
- jquery实现横向图片轮播特效代码分享
- jQuery插件实现图片轮播特效
- 基于jquery实现的仿优酷图片轮播特效代码
- 基于jQuery实现响应式圆形图片轮播特效
- 原生js和jquery实现图片轮播特效
- jQuery插件boxScroll实现图片轮播特效
- jQuery插件slicebox实现3D动画图片轮播切换特效
- jQuery实现友好的轮播图片特效
- 原生js和jquery实现图片轮播特效