您的位置:首页 > Web前端 > JQuery

图片轮播特效,jQuery实现

2016-11-24 19:41 597 查看
img 中的alt属性作用:当img图片无法显示时,将显示alt中的文字。<span>中index的作用:给这个元素添加一个属性,按照这个属性值给元素排序

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();
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: