我不能发挥作用

时间:2018-04-19 11:23:58

标签: javascript jquery html css

https://www.w3schools.com/code/tryit.asp?filename=FQI7JGNB7W5G

我如何制作代码; 从.roundbutton转到.roundbutton-active。

我尝试了js,但那不起作用。

.round-button {
  width: 45%;
}

.round-button-active {
  -webkit-animation-name: example;
  /* Safari 4.0 - 8.0 */
  -webkit-animation-duration: 3s;
  /* Safari 4.0 - 8.0 */
  -webkit-animation-fill-mode: forwards;
  /* Safari 4.0 - 8.0 */
  animation-name: example;
  animation-duration: 3s;
  animation-fill-mode: forwards;
}

@keyframes example {
  from {
    left: 0px;
  }
  to {
    left: 150px;
  }
}

@keyframes d {
  0% {
    background-color: red;
  }
  25% {
    background-color: yellow;
  }
  50% {
    background-color: blue;
  }
  100% {
    background-color: green;
  }
}

.float_center {
  float: right;
  position: relative;
  left: -30%;
  /* or right 50% */
  text-align: left;
}

.float_center>.child {
  position: relative;
  left: 50%;
}

.round-button-circle {
  width: 100%;
  height: 0;
  padding-bottom: 100%;
  border-radius: 50%;
  border: 10px solid #cfdcec;
  overflow: hidden;
  background: #ff006e;
  box-shadow: 0 0 3px gray;
}

.round-button-circle:hover {
  background: #9d0346;
}

.round-button a {
  display: block;
  float: left;
  width: 100%;
  padding-top: 50%;
  padding-bottom: 50%;
  line-height: 1em;
  margin-top: -0.5em;
  text-align: center;
  color: #e2eaf3;
  font-family: Verdana;
  font-size: 4.5em;
  font-weight: bold;
  text-decoration: none;
}
<video poster="key.png" id="bgvid" playsinline autoplay loop>
		<!-- WCAG general accessibility recommendation is that media such as background video play through only once. Loop turned on for the purposes of illustration; if removed, the end of the video will fade in the same way created by pressing the "Pause" button  -->
		<source src="videoplayback.mp4" type="video/webm">
		<source src="videoplayback.mp4" type="video/mp4">
	</video>
<div class="round-button float_center">
  <div class="round-button-circle">
    <a href="#" class="round-button" ">PLAY</a></div></div>

2 个答案:

答案 0 :(得分:2)

完全基于给出的内容,一个简单的解决方案是选择圆形按钮类并切换“活动”类。

这可以通过jQuery中的点击元素在jQuery中完成

$("div.round-button").click(function(){
   $(this).toggleClass("active");
});

假设您正在尝试使用圆形按钮类而不是锚标记来选择div。尽量不要让一个子元素与其父元素具有相同的类,因为这可能是JS首先不适合你的原因。

答案 1 :(得分:0)

没有jQuery添加javascript:

function toggleClass(element)
{
    if (element.classList == 'round-button') {
        element.classList.add('round-button-active');
        element.classList.remove('round-button');
    } else {
        element.classList.add('round-button');
        element.classList.remove('round-button-active');
    }
}

并添加到div: 的onClick =&#34; toggleClass(本)&#34 ;;

使用jQuery添加javascript:

$('div.round-button').click(function()
{
    if (this.attr('class') == 'round-button') {
        this.addClass('round-button-active');
        this.removeClass('round-button');
    } else {
        this.addClass('round-button');
        this.removeClass('round-button-active');
    }
 })
相关问题