(window).scroll(function() {
('#menu-open').prop('checked', true);
});
body {
background: #8bc34a;
color: white;
text-align: center;
}
a {
color: inherit;
text-decoration:none;
}
h1, h2, h3, h4 {
margin: 0;
margin-bottom: 10px;
margin-top: 130px;
}
h1 {
font-size: 3em;
}
.menu {
filter: url("#goo");
}
.menu-item, .menu-open-button {
background: #ffffff;
border-radius: 100%;
width: 80px;
height: 80px;
margin-left: -40px;
position: absolute;
top: 20px;
color: white;
text-align: center;
transform: translate3d(0, 0, 0);
transition: transform ease-out 200ms;
background-repeat: no-repeat;
background-size: 40px 40px;
background-position: 20px 10px;
}
.menu-open {
display: none;
}
.hamburger {
width: 25px;
height: 3px;
background: #83ccaf;
display: block;
position: absolute;
top: 50%;
left: 50%;
margin-left: -12.5px;
margin-top: -1.5px;
transition: transform 200ms;
}
.hamburger-1 {
transform: translate3d(0, -8px, 0);
}
.hamburger-2 {
transform: translate3d(0, 0, 0);
}
.hamburger-3 {
transform: translate3d(0, 8px, 0);
}
.menu-open:checked + .menu-open-button .hamburger-1 {
transform: translate3d(0, 0, 0) rotate(45deg);
}
.menu-open:checked + .menu-open-button .hamburger-2 {
transform: translate3d(0, 0, 0) scale(0.1, 1);
}
.menu-open:checked + .menu-open-button .hamburger-3 {
transform: translate3d(0, 0, 0) rotate(-45deg);
}
.menu {
position: absolute;
left: 50%;
margin-left: -190px;
padding-top: 20px;
padding-left: 190px;
width: 380px;
height: 250px;
box-sizing: border-box;
font-size: 20px;
text-align: left;
}
.menu-item:nth-child(3) {
transition-duration: 180ms;
}
.menu-item:nth-child(4) {
transition-duration: 180ms;
}
.menu-item:nth-child(5) {
transition-duration: 180ms;
}
.menu-item:nth-child(6) {
transition-duration: 180ms;
}
.menu-item:nth-child(7) {
transition-duration: 180ms;
}
.menu-item:nth-child(8) {
transition-duration: 180ms;
}
.menu-item:nth-child(9) {
transition-duration: 180ms;
}
.menu-item:nth-child(10) {
transition-duration: 180ms;
}
.menu-item:nth-child(11) {
transition-duration: 180ms;
}
.menu-open-button {
z-index: 2;
transition-timing-function: cubic-bezier(0.175, 0.885, 0.32, 1.275);
transition-duration: 400ms;
transform: scale(1.1, 1.1) translate3d(0, 0, 0);
cursor: pointer;
}
.menu-open-button:hover {
transform: scale(1.2, 1.2) translate3d(0, 0, 0);
}
.menu-open:checked + .menu-open-button {
transition-timing-function: linear;
transition-duration: 200ms;
transform: scale(0.8, 0.8) translate3d(0, 0, 0);
}
.menu-open:checked ~ .menu-item {
transition-timing-function: cubic-bezier(0.935, 0, 0.34, 1.33);
}
.menu-open:checked ~ .menu-item:nth-child(3) {
transition-duration: 180ms;
transform: translate3d(0.10352247px, -129.99995878px, 0);
background-image: url(img/website.png);
}
.menu-open:checked ~ .menu-item:nth-child(4) {
transition-duration: 280ms;
transform: translate3d(91.96047499px, -91.88727354px, 0);
background-image: url(img/mobileapp.png);
}
.menu-open:checked ~ .menu-item:nth-child(5) {
transition-duration: 380ms;
transform: translate3d(130px, 0px, 0);
background-image: url(img/mailer.png);
}
.menu-open:checked ~ .menu-item:nth-child(6) {
transition-duration: 480ms;
transform: translate3d(91.96047499px, 91.88727354px, 0);
background-image: url(img/digital-marketing.png);
}
.menu-open:checked ~ .menu-item:nth-child(7) {
transition-duration: 580ms;
transform: translate3d(0.10352247px, 129.99995878px, 0);
background-image: url(img/Untitled-2.png);
}
.menu-open:checked ~ .menu-item:nth-child(8) {
transition-duration: 680ms;
transform: translate3d(-91.81401383px, 92.03361812px, 0);
background-image: url(img/ticket.png);
}
.menu-open:checked ~ .menu-item:nth-child(9) {
transition-duration: 780ms;
transform: translate3d(-129.99983512px, 0.20704488px, 0);
background-image: url(img/networking.png);
}
.menu-open:checked ~ .menu-item:nth-child(10) {
transition-duration: 880ms;
transform: translate3d(-92.10670289px, -91.74069589px, 0);
background-image: url(img/analytics.png);
}
.menu-open:checked ~ .menu-item:nth-child(11) {
transition-duration: 980ms;
transform: translate3d(-0.31056715px, -129.99962903px, 0);
background-image: url(img/website.png);
}
.menu a p{
font-family: 'Montserrat';
color: #83ccaf;
font-size: 15px;
margin-top: 47px;
line-height:12px
}
<div style="height:700px;background:red;width:100%;"></div>
<div class="menu" id="gola">
<input type="checkbox" href="#" class="menu-open" name="menu-open" id="menu-open" />
<label class="menu-open-button" for="menu-open">
<span class="hamburger hamburger-1"></span>
<span class="hamburger hamburger-2"></span>
<span class="hamburger hamburger-3"></span>
</label>
<a href="#" class="menu-item"> <p>Event website</p> </a>
<a href="#" class="menu-item"> <p>Event App</p> </a>
<a href="#" class="menu-item"> <p>Emails</p> </a>
<a href="#" class="menu-item"> <p>Digital Post</p> </a>
<a href="#" class="menu-item"> <p>Custom forms</p></a>
<a href="#" class="menu-item"> <p>Event Ticketing</p> </a>
<a href="#" class="menu-item"> <p>Networking</p> </a>
<a href="#" class="menu-item"> <p>Analytics</p> </a>
</div>
<!-- filters -->
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<defs>
<filter id="shadowed-goo">
<feGaussianBlur in="SourceGraphic" result="blur" stdDeviation="10" />
<feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 18 -7" result="goo" />
<feGaussianBlur in="goo" stdDeviation="3" result="shadow" />
<feColorMatrix in="shadow" mode="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -0.2" result="shadow" />
<feOffset in="shadow" dx="1" dy="1" result="shadow" />
<feComposite in2="shadow" in="goo" result="goo" />
<feComposite in2="goo" in="SourceGraphic" result="mix" />
</filter>
<filter id="goo">
<feGaussianBlur in="SourceGraphic" result="blur" stdDeviation="10" />
<feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 18 -7" result="goo" />
<feComposite in2="goo" in="SourceGraphic" result="mix" />
</filter>
</defs>
</svg>
当我在特定div(id =“gola”)上滚动时,我的复选框没有自动检查,所以我找不到解决方案。我可以在jquery函数上使用滚动但它不能正常工作。手动检查。我可以在滚动特殊div上添加触发器事件。
答案 0 :(得分:0)
在选择元素之前,您缺少使用jQuery
的jQuery对象名称,或只是别名$
。
另请阅读How can I debug my JavaScript code?
下面的固定代码段:
$(window).scroll(function() { // missing $
$('#menu-open').prop('checked', true); // missing $
});
&#13;
body {
background: #8bc34a;
color: white;
text-align: center;
}
a {
color: inherit;
text-decoration:none;
}
h1, h2, h3, h4 {
margin: 0;
margin-bottom: 10px;
margin-top: 130px;
}
h1 {
font-size: 3em;
}
.menu {
filter: url("#goo");
}
.menu-item, .menu-open-button {
background: #ffffff;
border-radius: 100%;
width: 80px;
height: 80px;
margin-left: -40px;
position: absolute;
top: 20px;
color: white;
text-align: center;
transform: translate3d(0, 0, 0);
transition: transform ease-out 200ms;
background-repeat: no-repeat;
background-size: 40px 40px;
background-position: 20px 10px;
}
.menu-open {
display: none;
}
.hamburger {
width: 25px;
height: 3px;
background: #83ccaf;
display: block;
position: absolute;
top: 50%;
left: 50%;
margin-left: -12.5px;
margin-top: -1.5px;
transition: transform 200ms;
}
.hamburger-1 {
transform: translate3d(0, -8px, 0);
}
.hamburger-2 {
transform: translate3d(0, 0, 0);
}
.hamburger-3 {
transform: translate3d(0, 8px, 0);
}
.menu-open:checked + .menu-open-button .hamburger-1 {
transform: translate3d(0, 0, 0) rotate(45deg);
}
.menu-open:checked + .menu-open-button .hamburger-2 {
transform: translate3d(0, 0, 0) scale(0.1, 1);
}
.menu-open:checked + .menu-open-button .hamburger-3 {
transform: translate3d(0, 0, 0) rotate(-45deg);
}
.menu {
position: absolute;
left: 50%;
margin-left: -190px;
padding-top: 20px;
padding-left: 190px;
width: 380px;
height: 250px;
box-sizing: border-box;
font-size: 20px;
text-align: left;
}
.menu-item:nth-child(3) {
transition-duration: 180ms;
}
.menu-item:nth-child(4) {
transition-duration: 180ms;
}
.menu-item:nth-child(5) {
transition-duration: 180ms;
}
.menu-item:nth-child(6) {
transition-duration: 180ms;
}
.menu-item:nth-child(7) {
transition-duration: 180ms;
}
.menu-item:nth-child(8) {
transition-duration: 180ms;
}
.menu-item:nth-child(9) {
transition-duration: 180ms;
}
.menu-item:nth-child(10) {
transition-duration: 180ms;
}
.menu-item:nth-child(11) {
transition-duration: 180ms;
}
.menu-open-button {
z-index: 2;
transition-timing-function: cubic-bezier(0.175, 0.885, 0.32, 1.275);
transition-duration: 400ms;
transform: scale(1.1, 1.1) translate3d(0, 0, 0);
cursor: pointer;
}
.menu-open-button:hover {
transform: scale(1.2, 1.2) translate3d(0, 0, 0);
}
.menu-open:checked + .menu-open-button {
transition-timing-function: linear;
transition-duration: 200ms;
transform: scale(0.8, 0.8) translate3d(0, 0, 0);
}
.menu-open:checked ~ .menu-item {
transition-timing-function: cubic-bezier(0.935, 0, 0.34, 1.33);
}
.menu-open:checked ~ .menu-item:nth-child(3) {
transition-duration: 180ms;
transform: translate3d(0.10352247px, -129.99995878px, 0);
background-image: url(img/website.png);
}
.menu-open:checked ~ .menu-item:nth-child(4) {
transition-duration: 280ms;
transform: translate3d(91.96047499px, -91.88727354px, 0);
background-image: url(img/mobileapp.png);
}
.menu-open:checked ~ .menu-item:nth-child(5) {
transition-duration: 380ms;
transform: translate3d(130px, 0px, 0);
background-image: url(img/mailer.png);
}
.menu-open:checked ~ .menu-item:nth-child(6) {
transition-duration: 480ms;
transform: translate3d(91.96047499px, 91.88727354px, 0);
background-image: url(img/digital-marketing.png);
}
.menu-open:checked ~ .menu-item:nth-child(7) {
transition-duration: 580ms;
transform: translate3d(0.10352247px, 129.99995878px, 0);
background-image: url(img/Untitled-2.png);
}
.menu-open:checked ~ .menu-item:nth-child(8) {
transition-duration: 680ms;
transform: translate3d(-91.81401383px, 92.03361812px, 0);
background-image: url(img/ticket.png);
}
.menu-open:checked ~ .menu-item:nth-child(9) {
transition-duration: 780ms;
transform: translate3d(-129.99983512px, 0.20704488px, 0);
background-image: url(img/networking.png);
}
.menu-open:checked ~ .menu-item:nth-child(10) {
transition-duration: 880ms;
transform: translate3d(-92.10670289px, -91.74069589px, 0);
background-image: url(img/analytics.png);
}
.menu-open:checked ~ .menu-item:nth-child(11) {
transition-duration: 980ms;
transform: translate3d(-0.31056715px, -129.99962903px, 0);
background-image: url(img/website.png);
}
.menu a p{
font-family: 'Montserrat';
color: #83ccaf;
font-size: 15px;
margin-top: 47px;
line-height:12px
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div style="height:700px;background:red;width:100%;"></div>
<div class="menu" id="gola">
<input type="checkbox" href="#" class="menu-open" name="menu-open" id="menu-open" />
<label class="menu-open-button" for="menu-open">
<span class="hamburger hamburger-1"></span>
<span class="hamburger hamburger-2"></span>
<span class="hamburger hamburger-3"></span>
</label>
<a href="#" class="menu-item"> <p>Event website</p> </a>
<a href="#" class="menu-item"> <p>Event App</p> </a>
<a href="#" class="menu-item"> <p>Emails</p> </a>
<a href="#" class="menu-item"> <p>Digital Post</p> </a>
<a href="#" class="menu-item"> <p>Custom forms</p></a>
<a href="#" class="menu-item"> <p>Event Ticketing</p> </a>
<a href="#" class="menu-item"> <p>Networking</p> </a>
<a href="#" class="menu-item"> <p>Analytics</p> </a>
</div>
<!-- filters -->
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<defs>
<filter id="shadowed-goo">
<feGaussianBlur in="SourceGraphic" result="blur" stdDeviation="10" />
<feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 18 -7" result="goo" />
<feGaussianBlur in="goo" stdDeviation="3" result="shadow" />
<feColorMatrix in="shadow" mode="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -0.2" result="shadow" />
<feOffset in="shadow" dx="1" dy="1" result="shadow" />
<feComposite in2="shadow" in="goo" result="goo" />
<feComposite in2="goo" in="SourceGraphic" result="mix" />
</filter>
<filter id="goo">
<feGaussianBlur in="SourceGraphic" result="blur" stdDeviation="10" />
<feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 18 -7" result="goo" />
<feComposite in2="goo" in="SourceGraphic" result="mix" />
</filter>
</defs>
</svg>
&#13;