jQuery添加类单击不起作用.这是CSS还是jQuery错误



我认为错误是在逻辑中。当CSS设置在悬停时更改时,该动画可在工作时可以使用,但是当我尝试添加点击功能然后添加类时,什么也不会发生。这是JS小提琴:https://jsfiddle.net/lelales/6qmsgcjn/7/

这是在悬停:https://www.studiocaillouette.com/menu-test-css/

的示例中

$("document").ready(function() {
	$("#menu").click(function(){
  $(".cirlce").addClass("circle-grow");
.circle,.content {
    -webkit-transition: all 0.5s ease-in-out;
    -moz-transition: all 0.5s ease-in-out;
    -o-transition: all 2s ease-in-out;
    -ms-transition: all 2s ease-in-out;
    transition: all 2s ease-in-out;
}
.circle {    
    background: rgba( 99, 99, 99, 0.8 );
    box-shadow: 1px 2px 2px rgba( 0, 0, 0, 0.8 );
    border-radius: 100%;
    color: white;
    text-align: center;
    font-family: sans-serif;
    padding: 20px;
    overflow: hidden;
    
    -webkit-transform: scale( 0.1 );
    -moz-transform: scale( 0.1 );
    -o-transform: scale( 0.1 );
    -ms-transform: scale( 0.1 );
    transform: scale( 0.1 );
    
    width: 400px;
    height: 400px;
    line-height: 400px;
}
.circle-grow {
    -webkit-transform: scale( 1 );
    -moz-transform: scale( 1 );
    -o-transform: scale( 1 );
    -ms-transform: scale( 1 );
    transform: scale( 1 );
    
    vertical-align: middle;
}
.content {
    opacity: .1;
}
.circle-grow .content {
    opacity: 1;
}
<script 
<div id="menu"><a href="#">menu</a></div>
<div class="circle">
    <span class="content"><a href="index.html">home</a><br />
    						<a href="pricing.php">pricing</a><br />
    						<a href="gallery.php">gallery</a><br />
    						<a href="contact.php">contact</a><br />
    					</span>
</div>

单词'cirlce'shoud shoud of circle'的错字错误:

$(".cirlce").addClass("circle-grow");
  1. head中添加jQuery脚本:

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

  2. 使用});

  3. 关闭功能
  4. 您有错字错误使用circle 而不是 $(".cirlce")

$("document").ready(function() {
	$("#menu").click(function(){
  $(".circle").addClass("circle-grow");
});
});
.circle,.content {
    -webkit-transition: all 0.5s ease-in-out;
    -moz-transition: all 0.5s ease-in-out;
    -o-transition: all 2s ease-in-out;
    -ms-transition: all 2s ease-in-out;
    transition: all 2s ease-in-out;
}
.circle {    
    background: rgba( 99, 99, 99, 0.8 );
    box-shadow: 1px 2px 2px rgba( 0, 0, 0, 0.8 );
    border-radius: 100%;
    color: white;
    text-align: center;
    font-family: sans-serif;
    padding: 20px;
    overflow: hidden;
    
    -webkit-transform: scale( 0.1 );
    -moz-transform: scale( 0.1 );
    -o-transform: scale( 0.1 );
    -ms-transform: scale( 0.1 );
    transform: scale( 0.1 );
    
    width: 400px;
    height: 400px;
    line-height: 400px;
}
.circle-grow {
    -webkit-transform: scale( 1 );
    -moz-transform: scale( 1 );
    -o-transform: scale( 1 );
    -ms-transform: scale( 1 );
    transform: scale( 1 );
    
    vertical-align: middle;
}
.content {
    opacity: .1;
}
.circle-grow .content {
    opacity: 1;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="menu"><a href="#">menu</a></div>
<div class="circle">
    <span class="content"><a href="index.html">home</a><br />
    						<a href="pricing.php">pricing</a><br />
    						<a href="gallery.php">gallery</a><br />
    						<a href="contact.php">contact</a><br />
    					</span>
</div>

首先," circle"

出现错别字错误

请检查以下小提琴

小提琴

#circle {    
background: rgba( 99, 99, 99, 0.8 );
box-shadow: 1px 2px 2px rgba( 0, 0, 0, 0.8 );
border-radius: 100%;
color: white;
text-align: center;
font-family: sans-serif;
padding: 20px;
overflow: hidden;    
-webkit-transform: scale( 0.1 );
-moz-transform: scale( 01 );
-o-transform: scale( 0.1 );
-ms-transform: scale( 0.1 );
transform: scale( 0.1 );
width: 400px;
height: 400px;
line-height: 400px;
transition:ease all 1s
}

最新更新