jQuery从右到左滑动内部div [英] jQuery Slide Inner div from right to left

查看:94
本文介绍了jQuery从右到左滑动内部div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我到目前为止所得到的:

Here's what I've got so far:

JSFiddle

CSS:

#button-top { width: 100px; position: absolute; left: 75%; top: 40px; padding-left: 100px;overflow: hidden;}
#button-top:hover, #button-bottom:hover {cursor: pointer;}
.slide { position: relative; height: 100px; overflow: hidden; width: 350px; }
.slide img {position: relative; z-index: 100;}
.slide p {width: 80px; padding:8px 16px; color: #fff; margin: 0; }
.innerTop, .innerBottom { position: absolute; left: 0; top: 10px; width: 200px; height: 90px; padding: 6px; background: url(http://i39.tinypic.com/nz4ldw.png) 0 0 no-repeat; z-index: 50; display: none; }

#button-bottom { width: 100px; position: absolute; left: 75%; top: 240px; padding-left: 100px;overflow: hidden;}

脚本:

$('#button-top').click(function() {
  $('.innerTop').toggle('slide');
});
$('#button-bottom').click(function() {
  $('.innerBottom').toggle('slide');      
});

HTML:

<div class="hide-mobile" id="button-top">
[IMG]
<div class="slide innerTop"><p>HIDDEN SLIDING CONTENT</p></div>
</div>

<div class="hide-mobile" id="button-bottom">
[IMG]
<div class="slide innerBottom"><p>HIDDEN SLIDING CONTENT</p></div>
</div>

我希望蓝色内部div从右移到左边。

I'd like the blue inner div to slide from RIGHT to LEFT.

推荐答案

可以使用animate函数轻松完成。以下是解决方案:

It can be easily done using animate function. Here is the solution:

$('#button-top').toggle(function() {
  $('.innerTop').animate({'left':'3px'});
}, function() {
 $('.innerTop').animate({'left':'103px'});
});


$('#button-bottom').toggle(function() {
  $('.innerBottom').animate({'left':'3px'});
}, function() {
 $('.innerBottom').animate({'left':'103px'});
});

http://jsfiddle.net/nAaMV/6/

这篇关于jQuery从右到左滑动内部div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆