gpt4 book ai didi

ios - Stellar Parallax 在桌面上运行,在移动设备上运行静态图像

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:00:13 27 4
gpt4 key购买 nike

我的网站使用 Stellar.js 在覆盖用户屏幕宽度的大量图像上创建视差效果。 Stellar 以用户向下滚动页面的一半速度滚动图像,从而产生不错的效果。我最初使用这段代码:

MY CSS FILE
/* Separator About - Parallax Section */
.sep {
background-attachment: fixed!important;
background-position: 50% 0!important;
background-repeat: no-repeat!important;
width: 100%!important;
height: 180px!important;
position: relative!important;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;

}
.about {
background-image: url(../img/about-sep.jpg);
MY HTML FILE
<! -- ABOUT SEPARATOR -->


<div class="sep about" data-stellar-background-ratio="0.5"></div>
</div>
</div>


<script src="assets/js/jquery.stellar.min.js"></script>

<script>

$(function(){
$.stellar({
horizontalScrolling: false,
verticalOffset: 40
});
});
</script>
</body>

我发现如果我将背景附件从固定更改为滚动,视差效果将在桌面和 ios 上都有效。虽然在 ios 上有点不稳定,并且当用户在横向和纵向之间切换时配置起来很棘手。出于这个原因 - 让恒星响应,这似乎有所帮助。新代码是:

//JAVASCRIPT

$(function(){
$.stellar({
horizontalScrolling: false,
// Refreshes parallax content on window load and resize
responsive: true,
verticalOffset: 40
});
});
//CSS
.sep {
background-attachment: scroll;
background-position: 50% 0;
background-repeat: no-repeat;
height: 180px;
position: relative;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;

}
.about {
background-image: url(../img/about-sep.jpg);
//HTML

<div class="sep about" data-stellar-background-ratio="0.5"></div>
</div>
</div>

如果我认为它在移动设备上太不稳定/不可预测 - 我可以将此代码添加到我的 javascript 中:

// Stellar Parallax Script
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};


if( !isMobile.any() )
$(function(){
$.stellar({
horizontalScrolling: false,
// Refreshes parallax content on window load and resize
responsive: true,
verticalOffset: 40
});
});

此代码成功地在移动设备上为我提供了具有相同尺寸的静态图像 - 并在桌面设备上为我提供了视差滚动效果。

最佳答案

首先,非常感谢您分享您的代码!我在尝试解决这个问题时遇到了很多困难,而你帮助了我。我只是想分享我使用过的东西,以避免通过使用“滚动”而不是“固定”来滞后......这对我有用,在桌面上使用 stellar.js 完美视差,在移动和设备上固定 img。希望能有用!

<script>
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};

$(document).ready(function() {
if (isMobile) {
$(".section1Paral").css("background-attachment", "scroll");
};
});

if( !isMobile.any() )
$(function(){
$.stellar({
horizontalScrolling: false,
// Refreshes parallax content on window load and resize
responsive: true,
verticalOffset: 40
});
});
</script>

关于ios - Stellar Parallax 在桌面上运行,在移动设备上运行静态图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31977378/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com