使用外部按钮控制 CSS 变换?

发布于 2024-12-11 01:03:02 字数 1656 浏览 0 评论 0原文

需要按钮上的 javascript 帮助来触发这些转换,例如滑块 1、2、3 以及来回交替。就像苹果网站上的 iPhone 功能滑块一样。有人吗?

HTML:

<div id="anima-slide1">
  <div class="anima-text-slide1">Genuinity comes at a price.<br>
    <font color="#f06">Will you pay it?</font></div>
  <div class="anima-image-slide1"><img src="img/lowrider1.png" width="250" height="250"> </div>
</div>

<div id="anima-slide2">
  <div class="anima-text-slide2">Genuinity comes at a price.<br>
    <font color="#f06">Will you pay it?</font></div>
  <div class="anima-image-slide2"><img src="img/lowrider1.png" width="250" height="250"> </div>
</div>

<div id="anima-slide3">
  <div class="anima-text-slide3">Genuinity comes at a price.<br>
    <font color="#f06">Will you pay it?</font></div>
  <div class="anima-image-slide3"><img src="img/lowrider1.png" width="250" height="250"> </div>
</div>

CSS:(2 和 3 相同)

.anima-text-slide1 {
    margin-top:10px;
    position:absolute;
    font-family: 'BebasRegular';
    color:#FFF;
    font-size:40px;
}
.anima-text-slide1 {
    -webkit-backface-visibility: visible;
    -webkit-transition: 900ms ease;
    opacity: 0;
    -webkit-transform: translate(-497px, 0px) rotate(0deg);
}
.anima-image-slide1 {
    position:absolute;
    left: 610px;
    top: 0px;
}
.anima-image-slide1 {
    -webkit-backface-visibility: visible;
    -webkit-transition: 900ms ease;
    opacity: 0;
    -webkit-transform: translate(497px, 0px) rotate(0deg);
}

Need help with a javascript on a button to trigger these transformations like a slider 1,2,3 and alternate back and forth. Like on the apple website for iPhone features slider. Anyone?

The HTML:

<div id="anima-slide1">
  <div class="anima-text-slide1">Genuinity comes at a price.<br>
    <font color="#f06">Will you pay it?</font></div>
  <div class="anima-image-slide1"><img src="img/lowrider1.png" width="250" height="250"> </div>
</div>

<div id="anima-slide2">
  <div class="anima-text-slide2">Genuinity comes at a price.<br>
    <font color="#f06">Will you pay it?</font></div>
  <div class="anima-image-slide2"><img src="img/lowrider1.png" width="250" height="250"> </div>
</div>

<div id="anima-slide3">
  <div class="anima-text-slide3">Genuinity comes at a price.<br>
    <font color="#f06">Will you pay it?</font></div>
  <div class="anima-image-slide3"><img src="img/lowrider1.png" width="250" height="250"> </div>
</div>

The CSS: (Same for 2 and 3)

.anima-text-slide1 {
    margin-top:10px;
    position:absolute;
    font-family: 'BebasRegular';
    color:#FFF;
    font-size:40px;
}
.anima-text-slide1 {
    -webkit-backface-visibility: visible;
    -webkit-transition: 900ms ease;
    opacity: 0;
    -webkit-transform: translate(-497px, 0px) rotate(0deg);
}
.anima-image-slide1 {
    position:absolute;
    left: 610px;
    top: 0px;
}
.anima-image-slide1 {
    -webkit-backface-visibility: visible;
    -webkit-transition: 900ms ease;
    opacity: 0;
    -webkit-transform: translate(497px, 0px) rotate(0deg);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

来世叙缘 2024-12-18 01:03:02

通过添加类名,您可以创建多个动画步骤。使用 jQuery 可以更轻松地更改目标元素上的类名称。您可以将此技术应用于您的特定情况。

<div class="container">
Hello
</div>

<a href="javascript://" onclick="setFrame('frame1')">Frame 1</a>
<a href="javascript://" onclick="setFrame('frame2')">Frame 2</a>

JS:

function setFrame(frameName) {
    $('.container').addClass(frameName);
}

CSS:

.container {
     font-size:24px;   
}    
.frame1 {
    font-size:48px;
    -webkit-backface-visibility: visible;
    -webkit-transition: 900ms ease;
    opacity: 20;
    -webkit-transform: translate(200px, 0px) rotate(0deg);
}
.frame2 {
    font-size:64px;
    color:#ff0000;
    -webkit-backface-visibility: visible;
    -webkit-transition: 900ms ease;
    opacity: 20;
    -webkit-transform: translate(0px, 150px) rotate(30deg);
}

编辑:

所以如果你想处理多个元素,你可以这样做:

.containerA .frame1 {
... 
} 

.containerB .frame1 {
...some different style... 
} 

然后:

   function setFrame(frameName) {
        $('.containerA').addClass(frameName);
        $('.containerB').addClass(frameName);
    }

By adding a class name you can create several animation steps. Using jQuery makes it a lot easier to change the class names on the target element. You can apply this technique to your particular situation.

<div class="container">
Hello
</div>

<a href="javascript://" onclick="setFrame('frame1')">Frame 1</a>
<a href="javascript://" onclick="setFrame('frame2')">Frame 2</a>

JS:

function setFrame(frameName) {
    $('.container').addClass(frameName);
}

CSS:

.container {
     font-size:24px;   
}    
.frame1 {
    font-size:48px;
    -webkit-backface-visibility: visible;
    -webkit-transition: 900ms ease;
    opacity: 20;
    -webkit-transform: translate(200px, 0px) rotate(0deg);
}
.frame2 {
    font-size:64px;
    color:#ff0000;
    -webkit-backface-visibility: visible;
    -webkit-transition: 900ms ease;
    opacity: 20;
    -webkit-transform: translate(0px, 150px) rotate(30deg);
}

EDIT:

So if you want to do multiple elements you can do something like this:

.containerA .frame1 {
... 
} 

.containerB .frame1 {
...some different style... 
} 

Then:

   function setFrame(frameName) {
        $('.containerA').addClass(frameName);
        $('.containerB').addClass(frameName);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文