简体   繁体   English

为什么动画不起作用(CSS / JS / jQuery)?

[英]Why is animation not working (CSS/JS/jQuery)?

I am creating a slide-in menu, and what i want to do is when the user clicks on an image, the menu slides in. I have used everything, CSS animations, jQuery animation, and still not working. 我正在创建一个滑入式菜单,而我想要做的是当用户单击图像时菜单会滑入。我已经使用了所有内容,CSS动画,jQuery动画,但仍然无法使用。 ` `

            <div id="nav-slide-unvisible">
                <!-- Image that toggles animation -->
                <img id="image" src="arrow.png">

                <ul>

                    <li>Bla bla</li>
                    <li>Bla bla</li>
                    <li>Bla bla</li>
                    <li>Bla bla</li>
                    <li>Bla bla</li>

                </ul>

            </div>

        </nav>`

I used transform: translateX(-240px) in CSS, applying it to <nav id="slide-nav"> This is the jQuery code: 我在CSS中使用了transform: translateX(-240px) ,将其应用于<nav id="slide-nav">这是jQuery代码:

$("image").click(function() {
            $("slide-nav").animate({
            '-webkit-transform':'translateX(242px)'
            ,'-moz-transform':'translateX(242px)',1000);
                               });

But debugger generates an error "SyntaxError: missing : after property id" Thanks. 但是调试器会生成错误“ SyntaxError:属性ID后缺少:”谢谢。

The syntax error is a result of the missing curly brace in the object passed to the animate method: 语法错误是由于传递给animate方法的对象中缺少花括号而导致的:

$("#image").click(function() {
     $("#slide-nav").animate({'-webkit-transform':'translateX(242px)',
                             '-moz-transform':'translateX(242px)'},1000);
 });                                   // The one that goes here ^
$("image").click(function() {
            $("slide-nav").animate({
            '-webkit-transform':'translateX(242px)'
            ,'-moz-transform':'translateX(242px)',1000);
                               });

change it to 更改为

$("#slide-nav").animate({

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM