百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

parallax-vanilla

> 前端框架
开源

采用纯 JavaScript 实现的无缝和轻量级的平行滚动库,利用硬件加速实现更高的性能。

99 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

采用纯 JavaScript 实现的无缝和轻量级的平行滚动库,利用硬件加速实现更高的性能。

parallax-vanilla.js

Seamless and lightweight parallax scrolling library implemented in pure JavaScript utilizing Hardware acceleration for extra performance.

Demo

Main features

Super lightweight without dependencies

A few kilobytes of pure JavaScript.

Viewport-only animations

Parallax elements are only animated within the current viewport, saving a lot of resources.

Dynamic sizing

Image-elements are dynamically sized and adjusted relative to the pv-speed.

Performance is key

Vanilla Parallax maximizes your parallax effects with hardware acceleration and zero external libraries.

Media type independence

The parallax effect applies not only on images but on videos as well. Videos' audio will play if the videos are clicked and remain within the viewport.

Browser support

Tested browsers:

Chrome Safari Firefox
60+ 10+ 44+

Installation

bower

bash
bower i --save parallax-vanilla

npm

bash
npm i --save parallax-vanilla

Include

  • Include parallax-vanilla.css in ``
  • Include parallax-vanilla.js just before ``
xml

Usage

Simple usage

1. Wrap a pv-block with a pv-container.

xml

2. Attach a mediapath to pv-block

xml

3. Initialize library.

xml

>

JavaScript initialization options

Optional global settings can be configured upon initialization.

javascript
pv.init({
  container: {
    class: String,
    height: String || Number,
  },
  block: {
    class: String,
    speed: Number || Float,
    mediapath: String,
    mediatype: String,
    mute: Boolean,
  },
})

JavaScript Settings

		Name
		Type
		Default
  Description
		Example values
	



	

		settings
		Object
		{container, block}
		Settings object. These settings will be applied to each container and block. Can be individually overwritten by data attributes.
  {container: {...}, block: {...}
	

	

		
		
		
  
		
	

	

		settings.container
		Object
		{class, height}
		The container object.
  {...}
	

	

		settings.container.class
		String
		pv-container
		The class of the container element. Remember to update the CSS classes if you wish to change this.
  pv-container
	

	

		settings.container.height
		String || Number
		250px
		The container's height in either pixels or viewport heights. If the string lacks a suffix, or a number is entered, it will default to pixels.
  250px, 50vh, 250
	

	

		
		
		
  
		
	

	

		settings.block
		Object
		{class, speed, mediatype, mediapath}
		The block object.
  {...}
	

	

		settings.block.class
		String
		pv-block
		The class of the block element. Remember to update the CSS classes if you wish to change this.
  pv-block
	

	

		settings.block.speed
		Number || Float
		-Math.PI
		The speed and direction at which the parallax animated. Negative values will animate the `block` upwards when scrolling downwards on the page.
  1, 1.5, -1, -1.5
	

	

		settings.block.mediatype
		String
		image
		The block's media type. Blocks with mediapaths containing a video extension will automatically be considered videos.
  image, video or none
	

	

		settings.block.mediapath
		String
		undefined
		The block's media path.
  ../path/to/file.ext
	



		settings.block.mute
		Boolean
		false
		Defines whether or not all videos should be muted.
  true or false

Data attributes: Customize individual elements

Data attributes allow fine control over each individual element and will overwrite the global JavaScript settings.

xml

This code will produce a container with class pv-container with height 100vh containing a block with class pv-block with a parallax speed of 3.14 displaying the media epic_montage.mp4 of type video with pv-mute=false.

			Data attributes for container
		

	


  pv-height



		

			Data attributes for block
		

	


  pv-speed




  pv-mediatype




  pv-mediapath




  pv-mute

The descriptions and the default values are the same as the corresponding properties of the JavaScript settings object.

CSS

The CSS in parallax-vanilla.css is required in order for parallax-vanilla to function properly.

css
.pv-container {
  ...;
}
.pv-container .pv-block {
  ...;
}
.pv-container .pv-block video {
  ...;
}
.audio-icon {
  ...;
}

LICENSE

MIT

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScriptcssfront-endhacktoberfesthardware-acceleration

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架