Ich möchte die CSS-Klasse von class = "Name1" ändern, wenn ID "section-2" erreicht ist. Außerdem CSS von class = "Name2" ändern, wenn id "section-3" ist erreicht.CSS ändern, wenn die ID erreicht ist
Dieser Code funktioniert nur für einen Abschnitt.
CSS
.Name1 {
-moz-transition: all 2s linear;
-webkit-transition: all 2s linear;
transition: all 2s linear;
}
.Name2 {
-moz-transition: all 2s linear;
-webkit-transition: all 2s linear;
transition: all 2s linear;
}
.rotate {
-moz-transform:rotate(360deg);
-webkit-transform:rotate(360deg);
transform:rotate(360deg);
}
JS
$(window).scroll(function (event) {
var scroll = $(window).scrollTop();
$('.Name1').toggleClass('rotate',
scroll >= $('#section-2').offset().top
);
});
$(window).scroll();
HTML
<ol class="curtains">
<li id="section-1" class="cover" ">
<section class="center-block">
<div class="wrapper clearfix">
<div class="col1-1 centered">
</div>
</div>
</section>
</li>
<li id="section-2" class="cover" style="background-color:#e74c3c">
<section class="center-block">
<div class="wrapper clearfix">
<div class="col1-2">
<h4 class="Name1">Name1</h4>
</div>
</div>
</section>
</li>
<li id="section-3" class="cover" style="background-color:#16a085">
<section class="center-block">
<div class="wrapper clearfix">
<div class="col1-2">
<h4 class="Name2">Name 2</h4>
</div>
</div>
</section>
</li>
</ol>
und wenn ich will es beide 2 Abschnitte testen funktioniert nicht mit diesem Code.
$(window).scroll(function (event) {
var scroll = $(window).scrollTop();
$('.Name1').toggleClass('rotate',
scroll >= $('#section-2').offset().top
);
$('.Name2').toggleClass('rotate',
scroll >= $('#section-3').offset().top
);
});
$(window).scroll();
Was meinst du mit "erreicht"? –
bei der Ankunft in ID = "Name2" beim Scrollen –