如何从左侧将div元素设置为屏幕中间
我得到了这个无效的obect或prperty 我似乎无法通过jQuery引用jQuery(文档)对象
form.each(function () {
jQuery(this).animate({ marginLeft: jQuery(document).width / 2 }, 750); <-- this line here gives me errors
jQuery('input[name^=Next]').click(function () {
});
});
答案 0 :(得分:2)
您需要使用.animate
为div的marginLeft
属性设置动画。看看这些例子。这是一个快速模拟:
$('#myDiv').animate({
marginLeft: '+=' + $(document).width() / 2
}, 5000, function() {
// Animation complete.
});
答案 1 :(得分:1)
这是一个简单的例子:
<强> 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 );
});
});