javascript - Jquery .toggle .animate

标签 javascript jquery html css jquery-animate

我想.toggle .animation。你能帮我弄清楚为什么这个 jquery 代码不起作用吗?

Fiddle here

$(document).ready(function() {
$('.adiv').toggle(
   function(){
    $(this).animate({
        width: "150",
        height: "150",
    }, 1000);
    },
    function(){
    $(this).animate({
        width: "77", 
        height: "77",
    }, 1000);        
});
});

感谢您的帮助!

最佳答案

注意:您的代码运行良好!问题很简单:在你的 jsfiddle 中,你忘记导入 jquery!使用左侧的侧边栏再试一次!

顺便说一句,这是我使用 mouseover 和 mouseout 的解决方案:

Demo

$(document).ready(function() {
$('.adiv').mouseover(function()
     {$(this).animate({
            width: "150",
            height: "150"
        }, 1000);
    }).mouseout(
    function(){
        $(this).animate({
            width: "77", 
            height: "77"
        }, 1000);        
});
});

关于javascript - Jquery .toggle .animate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24737789/

相关文章:

javascript - Phonegap 和 Restful 网络服务

javascript - 函数返回未定义

javascript - AngularJS:无法访问 Controller 中的对象属性

javascript - 使表单提交根据单选按钮答案显示不同的页面

html - 如何将另一个 div 中的 2 个 div 对齐到底部和左/右

javascript - AngularJS单元测试: Initialize scope of a directive's controller

javascript - 单击事件不适用于 jquery 中动态更改的类

javascript - jQuery - 在按钮悬停时更改文本

javascript - 如何将表单值发送到服务器、数据库或电子邮件

javascript - 在所有内容上显示 div