开发者

Move div element to the middle of the screen in animation

开发者 https://www.devze.com 2023-02-01 17:33 出处:网络
How do you animate a div element to the middle of the screen from the left side I get this invalid obect or prperty

How do you animate a div element to the middle of the screen from the left side

I get this invalid obect or prperty i can't seem to reference the jQuery(document) object through jQuery anymore

开发者_运维百科form.each(function () {
    jQuery(this).animate({ marginLeft: jQuery(document).width / 2 }, 750); <-- this line here gives me errors
    jQuery('input[name^=Next]').click(function () {

    });
});


You'll want to use .animate to animate the div's marginLeft property. Just check out the examples. Here is a quick mock-up:

$('#myDiv').animate({
    marginLeft: '+=' + $(document).width() / 2
}, 5000, function() {
    // Animation complete.
});

Demo: http://jsfiddle.net/karim79/W6v2B/


Use jQuery Animate

Here is a simple example:

HTML:

<div id='walker'>Hello World</div>
<input type='button' id='move' value='move'>

jQuery:

jQuery(document).ready(function(){
   jQuery('#move').live('click', function(event) {        
       $("#walker").animate({marginLeft: $(window).width()/2,}, 1500 );
   });
});

Demo

  • Fun With jQuery’s Animate() Function
0

精彩评论

暂无评论...
验证码 换一张
取 消