简体   繁体   English

jQuery插件,用于动画化扩展元素以接管另一个元素

[英]jQuery plugin to animate expanding an element to take over another

I am trying to make a jquery plugin to animate an element to take over another ... take this for example 我正在尝试制作一个jQuery插件来为一个元素设置动画以接管另一个...以这个为例 在此处输入图片说明

I want to make the animation to carry the Phone div as is and make it in the position and dimension of c1, the div that is highlighted ... 我想使动画按原样携带Phone div,并使它位于c1(突出显示的div的位置和尺寸)中...

So i ended up making this code which partially worked : 所以我最终做了这段代码,部分有效:

 $.fn.expandTo = function (targetId) { targetId = $(targetId); var mView = $(this); log('POSITION'); log(mView.position()); log('OFFSET'); log(mView.offset()); if(mView.position() === undefined) mView = mView.parent(); mView.animate({ position : 'absolute', height : targetId.height(), width : targetId.width(), top : targetId.position().top, left : targetId.position().left }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

it worked for the first purpose , moving the phone div to that at the bottom , however reversing that animation couldn't successfully happen ... Please any help is appreciated and I can give any additional needed info 它的工作是第一个目的,将手机div移至底部,但是却无法成功完成动画的逆转...请提供任何帮助,我可以提供任何其他必要的信息

You have to create the "reverse" function. 您必须创建“反向”功能。

But you also have to think about taking a "memory" of the CSS values that your 1st function changes... In order to restore them in the 2nd function. 但是您还必须考虑对第一个函数更改的CSS值进行“存储” ...以便在第二个函数中恢复它们。

I've made a small... Really basic Fiddle example here . 我做了一个小...真正的Fiddle基本示例

// An object used as "memory"
var Mem={};

// Changes some CSS
$.fn.modified = function () {
    Mem.color = $(this).css("color");   // Store the color in "memory"
    Mem.size = $(this).css("font-size");    // Store the font-size in "memory"
    $(this).css({"color":"#00FF00","font-size":"3em"});
}

// Retreive the originally defined CSS
$.fn.initial = function () {
    $(this).css({"color":Mem.color,"font-size":Mem.size});
}



// Button triggers the modified() function
$("#modifyStyle").click(function(){
    $(".item").modified();
})

// Button triggers the "initial() function
$("#retreiveStyle").click(function(){
    $(".item").initial();
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM