【问题标题】:Save image position javascript after using absolute使用绝对后保存图像位置javascript
【发布时间】:2016-01-22 02:59:51
【问题描述】:

所以我尝试编写 JS 代码,在幻灯片中制作图片以增加大小,然后显示按钮。图片尺寸和我想出的按钮是我使用绝对位置设置为新尺寸图片位置的问题之一。我的问题是:

1)关窗后不知道怎么把图片带到他之前的地方。

2)在除图像之外的所有位置按下时关闭窗口(不是必须的。

3) 不移动图像,只是将相同的图片显示得更大,但碎石模糊(可能会解决所有问题)。

我正在为一个学校项目做这个,我需要知道代码是如何工作的包:);

抱歉,阅读时间长,但感谢帮助者

PS。还没有做幻灯片,但我只是想确保在构建它之前我可以完成所有这些 JS:

<script>
    $('#Test').click(function(){
        $('#Test').animate({
            height: screen.height * .45,
            right:  screen.width * .35,
            left:  screen.width * .2, // heigth / 2
            top:'200px' // width / 2
        });

    });

</script>

HTML:

<img src="Pics/up-arrow.png" id="Test"/>

CSS:

    #Test{
width = 400px;
position:absolute;
}

【问题讨论】:

    标签: javascript jquery html css jquery-animate


    【解决方案1】:

    您可能会查看使用 removeAttr() 并简单地删除动画添加到元素的内联样式

    $('#Test').removeAttr('style');
    

    或者,您可以使用$('#Test').data() 在活动之前存储您需要的任何内容,并在之后使用它来恢复内容

    var $el = $('#Test');
    $el
       .data('dimensions',{height: $el.height(), width:$el.width()})
       .animate(/* opts */)
    

    然后再重置:

    $el.animate( $el.data('dimensions'));
    

    DEMO

    【讨论】:

    • 这项工作(使用第一个选项)但你知道如何:1)使背景屏幕模糊 2)将图片动画回到他的位置吗?
    猜你喜欢
    • 2016-08-25
    • 2012-04-17
    • 1970-01-01
    • 2013-05-27
    • 1970-01-01
    • 2013-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多