当前位置:首页 > 技术分享 > 正文内容

div横向滚动,顶部滚动条(双滚动条同步)

admin3年前 (2022-10-05)技术分享2420

横向滚动的时候,希望滚动条出现在顶部方便内容多的时候在顶部就可以直接拉到不用滑动到底部再拉滚动条。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>顶部横向滚动条</title>
<style>
	.scroll1 {overflow-y: hidden;overflow-x: auto;white-space: nowrap;}
	.scroll1::-webkit-scrollbar {width: 0;height: 0;}
	.scroll2 {overflow-y: hidden;overflow-x: auto;white-space: nowrap;}
	.scroll2::-webkit-scrollbar {width: 0;height: 6px;}/*高宽分别对应横竖滚动条的尺寸*/
	.scroll2::-webkit-scrollbar-thumb {border-radius: 50px;background: #aaa;}
	.scroll2::-webkit-scrollbar-track {-webkit-box-shadow: inset 0 0 1px rgba(0, 0, 0, 0.2);border-radius: 50px;background: #fff;}/*滚动条里面轨道*/
</style>
</head>
<body>
	<!-- 这是用来展示滚动条的-->
	<div style="width:100%;" class="scroll2"><!-- 这是用来撑开div出现滚动条的-->
		<div id="content" style="min-width:130%;height:6px;"></div>
	</div>
	<!-- 这是一个可以左右滑动的div,内容长度是不固定的-->
	<div style="width:400px" class="scroll1">
		我是内容div,一个可以左右滑动的div,我要有足够的内容,才能滑动!我是不固定的!
	</div>
	<script>
		//实现滚动条同步的
		var scroll1 = document.querySelector('.scroll1');
		var scroll2 = document.querySelector('.scroll2');
		scroll1.addEventListener('scroll', function(e) {
			//使用比例来实现同步滚动 
			var scale = (scroll1.scrollWidth - scroll1.clientWidth) / (scroll2.scrollWidth - scroll2.clientWidth);
			scroll2.scrollLeft = scroll1.scrollLeft / scale;
	 	})
		scroll2.addEventListener('scroll', function(e) {
			//使用比例来实现同步滚动
			var scale = (scroll2.scrollWidth - scroll2.clientWidth) / (scroll1.scrollWidth - scroll1.clientWidth);
			scroll1.scrollLeft = scroll2.scrollLeft / scale;
		})
	</script>
</body>
</html>


扫描二维码推送至手机访问。

版权声明:本文由小刚刚技术博客发布,如需转载请注明出处。

本文链接:http://blog.bitefu.net/post/433.html

分享给朋友:

相关文章

centos 配置Let's Encrypt 泛域名https证书

centos 配置Let's Encrypt 泛域名https证书

前言2018年1月份Letsencrypt可以申请泛域名证书,这让我们部署多域名、多站点https省了很多功夫,终于可以不用维护多个域名的https证书。笔者以acme.sh为例,手把手教你配置https证书~本教程适用于centos 6....

PHP AES加解密 (ECB模式/sha1prng算法/PKCS5Padding和PKCS7Padding补码) ECB 模式不需求设置 iv

php7+ 版本/**  * [AesSecurity aes加密,支持PHP7+]  * 算法模式:ECB  * 密钥长度:128  * 补...

php Aes 加密模式ECB填充pkcs5padding base64

最近做支付项目用到了aes加密不过试了好多办法总是和官方给出的结果不一样,找了很久终于找到了测试结果同 http://tool.chacuo.net/cryptaes/ <?php /**  * [Aes&nb...

​CentOS 安装libsodium 支持 crypto_aead_aes256gcm_decrypt 兼容php5.6,php7.2

微信小微商户下载证书返回的密文用 AEAD_AES_256_GCM 算法 解密的方法。其中用到了 string sodium_crypto_aead_aes256gcm_decrypt ( string $ci...

Lodop、C-Lodop 95版本chrome跨域请求问题 has been blocked by CORS policy: Response 解决

1、打开chrome://flags/#site-isolation-trial-opt-out2、搜索Block insecure private network requests3、设置disabled4、重启chrome...

完美解决微信js-sdk在IOS系统报 wx.config报 realAuthUrl invalid signature的问题

遇到这个问题首先是困惑,安卓可以,苹果不可以,然后查找文档,验证你们一个个尝试的结果,但是没有描述明白;打开小程序我这边实现了原生安卓、苹果和公众号,唯独这个公众号iOS端打开小程序掉坑总结修复问题:App.vue中增加 moun...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。