jQuery:点击放大和移动

标签 jquery html css jquery-animate


我还有一个关于 jQuery 的问题:
所以我有这个代码:

$(document).ready(function(){
$(this).click(function(){
    $("#block1").animate({width:7em,height:7em});
    $("#block2").animate({width:7em,height:7em});
    $("#block3").animate({width:7em,height:7em});
    $("#block4").animate({width:7em,height:7em});
    $("#block5").animate({width:7em,height:7em,function(){
        $(this).animate({width:20em,height:20em,top:4em,left:8em});
    });
});
});

这应该是一些“便利贴”形状的盒子
1:将所有盒子恢复到原来的位置和大小
2:从原来的位置弹出到屏幕中间,点击放大..
你知道为什么这不起作用吗? (我不想要 css 悬停,但如果有另一种方法可以通过 css 实现此目的,我可以接受!!)

最佳答案

$(document).ready(function(){
  $(this).click(function(){
    $("#block1").animate({width:"7em",height:"7em"});
    $("#block2").animate({width:"7em",height:"7em"});
    $("#block3").animate({width:"7em",height:"7em"});
    $("#block4").animate({width:"7em",height:"7em"});
    $("#block5").animate({width:"7em",height:"7em"},function(){
       $(this).animate({width:"20em",height:"20em",top:"4em",left:"8em"});
    });
  });
});

1) 第 7 行缺少右大括号 "$("#block5").animate({width:"7em",height:"7em"'}' ,function(){"

2)你还需要包含 jquery 文件

3)要制作动画,您需要给定的高度和宽度大于元素当前的高度和宽度才能看到效果,即超过 7em,就像在 css 中您已经给定的 7em

4)正如我在 jsFiddle 链接中发现的那样,也没有为元素提供 Id

以上提到的所有观点均基于链接http://jsfiddle.net/q5RwE/2/你给的

关于jQuery:点击放大和移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10731222/

相关文章:

javascript - 根据价格过滤

javascript - Rails - jQuery 不适用于 Heroku 的生产环境

jquery - 避免使用 JQuery 同时显示 2 个项目

html - 嵌套表格行 HTML CSS

css - 当使用附件固定且边距不起作用时,标题图像位于导航栏后面

javascript - 单击后退按钮时如何记住上一页的滚动位置

php - 日历加载或 JavaScript 错误

PHP 函数不返回任何值

HTML 电子邮件,删除 tr 标签之间的间距?

javascript - 如何将html页面设置为背景图片?