html设置顶部滚动图片,jQuery和css3页面顶部图片滚动缩小视觉差特效

这是一款效果炫酷的 jQuery和css3页面顶部图片滚动缩小视觉差特效插件。在当下已经有很多网站用大的背景图片来作为网站的头部。在这个教程中我们将在页面向下滚动时创建一个非常好看图片缩小动画,制作一种图片沿Z轴缩放的假象。

HTML结构

创建section#cd-intro元素作为wrapper,包含住图片和文本内容。

将#cd-intro-background的背景图像设置为全屏宽度的图片。

CSS样式

对于桌面设备,我们为section#cd-intro设置position:fixed,并为#cd-intro-background通过CSS3 scale Transformation设置origin 属性为X轴50%、Y轴100%。这些是我们要为图片缩小效果所做的工作。

@media only screen and (min-width: 1170px) {

#cd-intro {

position: fixed;

top: 70px;

left: 0;

}

#cd-intro .cd-intro-background {

transform-origin: 50% 100%;

}

}

#cd-intro-background上的scale transformation值将通过jQuery动态来调用。

JAVASCRIPT

我们定义triggerAnimation()方法来触发CSS3 scale Transformations事件并将它绑定到屏幕的滚动事件上。

function triggerAnimation(){

if($(window).width()>= MQ) {

$(window).on('scroll', function(){

//The window.requestAnimationFrame() method tells the browser that you wish to perform an animation- the browser can optimize it so animations will be smoother

window.requestAnimationFrame(animateIntro);

});

} else {

$(window).off('scroll');

}

}

我们使用requestAnimationFrame()来作为滚动事件的处理函数。requestAnimationFrame()可以告知浏览器我们需要执行什么动画,这样浏览器可以对动画进行效果优化。

animateIntro()函数根据窗口的scrollTop()的值来缩放#cd-intro-background元素并且改变它的透明度。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值