我有这段代码,当您滚动到100px以上时,它会更改导航栏的颜色,这在Chrome和Android设备上可以正常使用,但在Safari和iOs设备上却无法使用!
<nav class="navbar navbar-expand navbar-dark bg-dark fixed-top">
<a href="./index.html" class="navbar-brand">
<img src="assets/navbar-new-desk.png" class="navbar-logo">
</a>
$("body").scroll(function () {
$('nav').toggleClass('scrolled', $(this).scrollTop() > 100);
$('.apply').toggleClass('scrolled1', $(this).scrollTop() > 100);
if($(this).scrollTop()>100){
$(".navbar .navbar-brand img").attr("src","assets/desktop-scroll.png");
$(".navbar .nav-hamburger-icon img").attr("src","assets/black-nav-mob.png");
}
else{
$(".navbar .navbar-brand img").attr("src","assets/navbar-newdesk.png");
$(".navbar .nav-hamburger-icon img").attr("src","./assets/mobile-icon.png");
}
});