jquery 将左下角切换到右上角

发布于 2024-09-17 05:49:41 字数 219 浏览 2 评论 0原文

我已经让这个脚本一切正常,但我想知道是否可以将左下角切换到右上角,

    $("a#slick-toggle").click(function() {
    $("#slickbox").animate({width: "toggle", 
                height: "toggle"}, 1000);
});

谢谢 Gareth

i have got this script all works fine but i was wonder if its possible to toggle bottom left to top right

    $("a#slick-toggle").click(function() {
    $("#slickbox").animate({width: "toggle", 
                height: "toggle"}, 1000);
});

thank Gareth

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半衾梦 2024-09-24 05:49:42

您可以将位置设置为相对位置,然后为 left 属性设置动画,如下所示:

$("a#slick-toggle").click(function() {
  var sb = $("#slickbox").stop(true, true), w = sb.is(":visible") ? sb.width():0;
  sb.animate({width: "toggle", height: "toggle", left: w}, 1000);
});​

您可以在这里尝试一下,它的作用是抓取 .width()< /code>元素并将其在动画中向左移动那么远,从而产生向右折叠的效果,而不是向左折叠。 .stop(true, true) 部分是为了防止动画队列-up 并且 .width() 是执行时的适当值访问它(不是中间动画宽度)。

You can set the position as relative then also animate the left property, like this:

$("a#slick-toggle").click(function() {
  var sb = $("#slickbox").stop(true, true), w = sb.is(":visible") ? sb.width():0;
  sb.animate({width: "toggle", height: "toggle", left: w}, 1000);
});​

You can give it a try here, what this does is grab the .width() of the element and moves it that far to the left in the animation, giving the effect of it collapsing to the right, rather than the left. The .stop(true, true) portion is to prevent animation queue-up and that .width() is the appropriate value when going to access it (not a mid-animation width).

聆听风音 2024-09-24 05:49:42

为此,您可以浮动您的#slickbox右侧

JS

$(document).ready(function() {
  $("a#slick-toggle").click(function() {
    $("#slickbox").animate({width: "toggle",
                height: "toggle"}, 1000);
    return false;
  });
});

HTML
请注意:float: right

<a href="#" id="slick-toggle">Clicked</a><br />
<div style="width: 25px; float: left;">
 <div id="slickbox" style="float: right;">Testt</div>
</div>

查看演示

In order to do that, you can float your #slickbox to right!

JS

$(document).ready(function() {
  $("a#slick-toggle").click(function() {
    $("#slickbox").animate({width: "toggle",
                height: "toggle"}, 1000);
    return false;
  });
});

HTML
Please note : float: right

<a href="#" id="slick-toggle">Clicked</a><br />
<div style="width: 25px; float: left;">
 <div id="slickbox" style="float: right;">Testt</div>
</div>

See Demo

烟花易冷人易散 2024-09-24 05:49:41

http://api.jquery.com/animate/ 有一个移动示例。右上角可以通过 css 设置为 top: 0px; right: 0px; 所以它会是这样的:

.animate({
  top: 0,
  right: 0,
  height: 'toggle'
});

http://api.jquery.com/animate/ has an example of movement. Top right can be set via css as top: 0px; right: 0px; so it would be something like:

.animate({
  top: 0,
  right: 0,
  height: 'toggle'
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文