jQuery 显示/隐藏缩放无法按预期工作
jquery show/hide scale doesnt work as expected
我试图让一个div同时在宽度和高度上按比例出现。同样要消失,但我做不到。还有其他更好的方法吗?谢谢。
http://jsfiddle.net/693xw/
JAVASCRIPT
$('a.close').click(function() {
$('#box').hide("scale",{percent: 0, direction: 'vertical', origin: ['bottom','left']},1000);
$('#box').hide("scale",{percent: 0, direction: 'vertical', origin: ['top','right']},1000);
});
//});
$('#show').click(function() {
$('#box').show("scale",{percent: 100, direction: 'vertical', origin: ['bottom','left']},1000);
$('#box').show("scale",{percent: 100, direction: 'vertical', origin: ['top','right']},1000);
});
这是小提琴演示
$('a.close').click(function() {
$('#box').hide("scale",
{percent: 0, direction: 'both', origin: ['bottom','middle']},1000);
});
$('#show').click(function() {
$('#box').show("scale",
{percent: 100, direction: 'vertical', origin: ['bottom','middle']},1000);
});
您只需要将 direction
参数更改为 'both'
:
http://jsfiddle.net/693xw/7/
$('a.close').click(function() {
$('#box').hide("scale",
{percent: 0, direction: 'both', origin: ['middle','middle']},1000);
});
$('#show').click(function() {
$('#box').show("scale",
{percent: 100, direction: 'vertical', origin: ['bottom','left']},1000);
});
还有其他方法可以实现此目的:您可以将此缩放效果描述为 CSS 文件中的 CSS 动画,而不是使用 jQuery 实现它。
编辑:http://api.jqueryui.com/scale-effect/不仅有关于这种效果的jQuery文档,还包括两个演示。第一个基本上只是"scale"
,没有其他参数,并且似乎已经做了你想要的,至少对我来说使用 Chrome。这是他们代码的关键部分:
<p>Click anywhere to toggle the box.</p>
<div id="toggle"></div>
<script>
$( document ).click(function() {
$( "#toggle" ).toggle( "scale" );
});
</script>
$( "#clickme" ).click(function() {
$( "#book" ).hide( "slow", function() {
//your css method or function
});
});
试试这个方法
这是我为解决这个问题所做的:http://jsfiddle.net/693xw/13/
.HTML
<input type="button" name="show" id="show" class="show" value="Show">
<div id="box" style="display:none;">
<a href="#" class="close">Close</a>
</div>
.JS
$('a.close').click(function() {
$('#box').animate({
width:"5px",
height:"5px",
opancy: "toggle"
},1000);
});
//});
$('#show').click(function() {
$('#box').show().animate({
width:"200px",
height:"200px",
},1000)
});
相关文章:
- 谷歌地图不是以HTML显示,而是在JS Fiddle上工作
- 使用谷歌应用程序脚本从工作表中获取值并将其显示在文本框中
- 如何使用modalDialog来显示可以在所有浏览器中工作的弹出窗口
- PHP Javascript显示/隐藏按钮不工作
- ng隐藏和ng显示无法正常工作
- JQuery隐藏/显示无法正常工作
- 我的时间倒计时脚本在谷歌浏览器中工作正常,但在其他浏览器中打开时它显示为南楠
- 为什么竞争不能在离子中显示(隐藏在标题下方)(离子竞争不能正常工作)
- 背景's/JavaScript在本地显示/工作,而不是在服务器上
- 角度方向ng显示不工作
- 单击水平滚动库中的图像以居中显示无法工作的功能
- 显示:没有不工作的iPhone模拟器
- 自动完成搜索无法正常工作,请不要迭代$中的所有元素.每个ul-li都会及时显示响应
- 基本javascript不是't工作-显示块
- 在服务页面上向上滑动滑块不工作/显示
- 不工作:显示值从jquery-ajax模态
- 引导日期选择器不工作[显示]在第一次点击
- Firefox后退按钮没有按预期工作:显示的是javascript而不是html
- Jstree 3.0.0上下文菜单右键不工作.显示TypeError: vakata_context.element.h
- Javascript onclick事件工作显示,但不隐藏